我正在尝试初始化window窗体中的Web浏览器组件,但收到此异常消息
System.Threading.ThreadStateException: 'ActiveX control '8856f961-340a-11d0-a96b-00c04fd705a2' cannot be instantiated because the current thread is not in a single-threaded apartment.'我在此行上收到上面提到的异常消息
this.browse = new System.Windows.Forms.WebBrowser();请告诉我如何解决这个问题
发布于 2019-12-05 14:44:22
使用STAThread标记您的Main()方法,如下所示:
[STAThread]
static void Main()
{
// your code
}或者,如果Web浏览器组件应该从您创建的ant线程内部调用,请为该线程设置适当的单元状态:
yourThread.SetApartmentState(ApartmentState.STA);发布于 2019-12-05 14:43:25
在main方法上添加STAThread属性。
https://stackoverflow.com/questions/59189477
复制相似问题