How to set Single Threaded Apartment model

  • 12 years ago

    While my project is in an STA state, when I added a class with no form it is executing in an MTA state. I can't find any reference to MTA or STA anywhere in the entire solution. How do I set a class to run in STA rather than MTA mode?

    When I try to instantiate a form object from a class with no form, I get an exception of "control cannot be instantiated because the current thread is not in a single-threaded apartment". When I put <STAThread()> in front of the function that throws the exception, GetApartmentState still says MTA. From the main form GetApartmentState says STA, so somehow the formless class has been switched into an MTA state while the rest of the project is in an STA state.

Post a reply

No one has replied yet! Why not be the first?

Sign in or Join us (it's free).

Contribute

Why not write for us? Or you could submit an event or a user group in your area. Alternatively just tell us what you think!

Our tools

We've got automatic conversion tools to convert C# to VB.NET, VB.NET to C#. Also you can compress javascript and compress css and generate sql connection strings.

“C++: an octopus made by nailing extra legs onto a dog.” - Steve Taylor