在不同的线程中运行和控制浏览器控件

我有一个主要的gui类和一些子类。 有+ – 3个线程正在从各种互联网资源和API网关等收集数据。

现在,在其中一个线程中,我想运行一个webbrowser控件,所以我可以为我的程序添加一些自动浏览function。 每个子线程应该能够自己打开web浏览器。 所以我创建了第二个c#窗体,它只包含webbrowsing控件。

我已经在这个新线程上使用了用于webbrowser控件的ApartmentState.STA设置。 但是,form2没有响应。

我试着调用Application.Run(); 从这个线程,这使得webbrowser / form2响应。 但后来我的主线程停止运行。

所以我对如何继续有点不确定。 我想要的是什么?

这应该工作

var th = new Thread(() => { WebBrowserDocumentCompletedEventHandler completed = null; using (WebBrowser wb = new WebBrowser()) { completed = (sndr, e) => { //Do Some work wb.DocumentCompleted -= completed; Application.ExitThread(); }; wb.DocumentCompleted += completed; wb.Navigate(url); Application.Run(); } }); th.SetApartmentState(ApartmentState.STA); th.Start(); th.Join(); 

那说,我会使用WebClient或HttpWebRequest与HtmlAgilityPack一起下载和解析html资源