Sunday, March 20, 2011

ActiveX control cannot be instantiated because the current thread is not in a single-threaded apartment.

As the subject is self explainatory, I need help.

I'm writing a small tool that displays a splash screen when starting. The splash screen is a Form. When there was only a Button control on it it was working fine. But when I removed it and placed a WebBrowser control on it, it throws the above exception.

Thanks in advance.

From stackoverflow
  • Are you using WinForms? If so, try placing the [STAThread] attribute at the top of your class definition and see what happens:

    namespace WindowsFormsApplication1 { [STAThread] public partial class Form1 : Form {

    Emre : it says I can use this attribute only with Method definitions, not class declarations
    kmontgom : My mistake. Its actually applied to the Main function of your application class


Post a Comment