没有线程的 Web 浏览器控件
本文关键字:浏览器 控件 Web 线程 | 更新日期: 2023-09-27 18:31:00
我没有在我的应用程序中使用任何线程,但我收到以下异常:
其他信息:无法实例化 ActiveX 控件"8856f961-340a-11d0-a96b-00c04fd705a2",因为当前线程不在单线程单元中。
当我在我的 Web 应用程序中初始化WebBrowser
时。
WebBrowser wb = new WebBrowser();
这是我调用此方法的正常流程。
Page_Load()
{
TestWebBrowser("www.something.com")
}
static string TestWebBrowser(string url);
{
WebBrowser wb = new WebBrowser();
wb.ScrollBarsEnaenter code herebled = false;
wb.ScriptErrorsSuppressed = true;
wb.Navigate(url);
while (wb.ReadyState != WebBrowserReadyState.Complete) { Application.DoEvents(); }
mshtml.IHTMLDocument3 documentAsIHtmlDocument3 = (mshtml.IHTMLDocument3)wb.Document.DomDocument;
var content = documentAsIHtmlDocument3.documentElement.innerHTML;
return content ;
}
将代码包装在 Try/Catch 块中,并找出异常/内部异常(希望)原因。