7. August 2013 11:28
You must have noticed that entry point Main() method in program.cs class of all .NET windows forms applications are always decorated with the attribute STAThread. What is this attribute and why is it needed?
Attribute [STAThread] is a mandatory attribute for all windows forms application. STAThread attribute need to be applied to set the current thread apartment state as single threaded. This means that the COM threading model for the application is single-threaded apartment.
This attribute specifies the communication mechanism between the current thread and other threads that may want to talk to it via COM.
Windows Forms applications may use COM interop in order to communicate with operating system components such as File Dialogs,Clipboard etc. STAThread attribute
Apartment style is mandatorily needed to be declared for windows forms appliations.If not declared it may be that some other component which communicate your windows application will declare an apartment style for your windows application improperly.