Click here to Skip to main content
16,019,263 members
Please Sign up or sign in to vote.
2.33/5 (2 votes)
See more:
I have find every about [STAThread]. but does not get the good answer.. i hope you will help me ..
Thanks in advance..
Posted
Comments
Sergey Alexandrovich Kryukov 26-Nov-13 0:36am    
What's wrong with just reading about this stuff in MSDN?..
—SA

[STAThread] is a carry-over from COM, Microsoft's "Component Object Model," introduced in 1993 as way to structure interaction and creation of software components; it was/is the "backbone" of ActiveX, OLE, and other layers of software abstraction. See: [^].

COM provided both single-threaded apartment (STA), and multi-threaded (MTA) programming models.

If use the Microsoft Ribbon Control in Win7/8, you are using a COM component. If you use the Microsoft provided Controls in programming WinForms in C# .NET, you are probably using Controls created with COM, and ActiveX, that now inter-operate with .NET.

The .NET CLR uses COM Interop as a kind of "bridge" between the world of managed .NET Types and COM facilities, and object [^].

To get a deeper sense of what [STAThread] means in .NET programming, I suggest you study this excellent essay by Hans Passant: [^].

To over-simplify: WinForms programming requires the use of [STAThread] ... that, of course, does not stop you from creating and using other threads, as long as they don't "touch" the UI thread.
 
Share this answer
 
 
Share this answer
 
Comments
Sergey Alexandrovich Kryukov 26-Nov-13 0:35am    
Fair enough, a 5.
—SA

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900