I am having trouble getting a web browser in my form to work. When I run, I get this error ActiveX control '8856f961-340a-11d0-a96b-00c04fd705a2' cannot be instantiated because the current thread is not in a single-threaded apartment.
It takes me to the form designer.cs file to this text this.webBrowser2 = new System.Windows.Forms.WebBrowser(); and I really do not know what to do to get thebrowser working.
I have tried both MTAThread and STAThread in the Program.cs file cant seem to get it to work.
Thanks
You need to mark your thread as an
STAThread
, because COM controls require that apartment state.There are two easy ways to do this:
[STAThread]
attribute. If you don't set it on the entry point but on some other method down the call stack, then this attribute won't be applied.STAThread
usingThread.SetApartmentState()