I have been looking through msdn an a few books an havent been able to find an explaination on what [STAThread] is or does.
Can someone explain to me its purpose or link me to a site that can help. thanks
I was looking for the same thing, and your post came out first on my Google search. Anyway, Apparently it is setting a the attribute for the Main method that defines the threading model for the form. I found this in VS.Net Help under "Form Class".
Say you have a program that has a function that does some intesive stuff, such as a recursive math equation or a fibonacci etc.. and you want to update a progress bar or textbar with its progress, you'll notice that if you set a property in that functions thread it won't be received until the function has been completed, visavi no progress indicator. Thats where multithreading comes in, to do something like that you use another thread, I won't go into detail about that now.
STAThread stands for SingleThreadApplicationThread, meaning that your application is bound to its own single thread, in effect giving it more protection from accidental screw ups and such. It is also required for certain things like Dynamic menu items to work in Win98/ME.
Indicates that the default threading model for an application is single-threaded apartment (STA).
Any public static (Shared in Visual Basic) members of this type are safe for multithreaded operations. Any instance members are not guaranteed to be thread safe.
Threading models only pertain to applications that use COM interop. Applying this attribute to an application that does not use COM interop has no effect.
The startup threading model can be set to single-threaded apartment or multithreaded apartment. If it is not set, then the thread is not initialized.