tags:

views:

1311

answers:

3

Why do Winforms programs have the [STAThread] attribute on the Main() method and what are the consequences of removing it?

+12  A: 

To quote from an MSDN blog,

When the STAThreadAttribute is applied, it changes the apartment state of the current thread to be single threaded. Without getting into a huge discussion about COM and threading, this attribute ensures the communication mechanism between the current thread and other threads that may want to talk to it via COM. When you're using Windows Forms, depending on the feature you're using, it may be using COM interop in order to communicate with operating system components. Good examples of this are the Clipboard and the File Dialogs.

See http://blogs.msdn.com/jfoscoding/archive/2005/04/07/406341.aspx

Alex Fort
Would be nice if you put a link to the blog in your answer.
Geoffrey Chetwood
A: 

It means that Windows Forms programs use a single-threaded apartment state. MTA and free threaded apartment states are not supported.

Ben Hoffstein
+1  A: 

Here is detailed answer.

cleg