Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Can we use thread inside [STAThread] main?

Tags:

c#

.net

when we use STAThread in the Main, does it mean we cannot create new thread from Main?

like image 635
Adam Lee Avatar asked Feb 03 '12 08:02

Adam Lee


Video Answer


1 Answers

No, it doesn't. Most UI applications start in an STA thread - it doesn't stop them from starting new threads. STAThread is mostly about COM interop. I've found you can mostly ignore it when you're not using anything that uses COM - but be aware that UI controls which interact with the clipboard etc may well use COM.

Note that the attribute just affects the apartment model for the newly created thread which runs the application. It's got very little to do with the Main method itself, really - it could have been an assembly attribute, or something like that instead.

like image 120
Jon Skeet Avatar answered Oct 07 '22 23:10

Jon Skeet