gpt4 book ai didi

c# - 没有线程的 WebBrowser 控件

转载 作者:太空宇宙 更新时间:2023-11-03 15:48:30 24 4
gpt4 key购买 nike

<分区>

我没有在我的应用程序中使用任何线程,但我收到了这个异常:

Additional information: ActiveX control '8856f961-340a-11d0-a96b-00c04fd705a2' cannot be instantiated because the current thread is not in a single-threaded apartment.

当我在我的 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 ;
}

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com