I am trying to Initialize Web Browser Component in window form but I am getting this exception message
System.Threading.ThreadStateException: 'ActiveX control '8856f961-340a-11d0-a96b-00c04fd705a2' cannot be instantiated because the current thread is not in a single-threaded apartment.'
I am getting above mentioned Exception Message on this line
this.browse = new System.Windows.Forms.WebBrowser();
Please tell me how to solve this issue
Flag your Main() method with [STAThread] like below:
[STAThread]
static void Main()
{
// your code
}
or, if the Web Browser Component should be called from inside of ant thread you created, set proper Apartment State for this thread:
yourThread.SetApartmentState(ApartmentState.STA);
Add STAThread attribute above your main method.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With