Adam Lee
Adam Lee

Reputation: 25768

Can we use thread inside [STAThread] main?

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

Upvotes: 6

Views: 326

Answers (1)

Jon Skeet
Jon Skeet

Reputation: 1502816

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.

Upvotes: 7

Related Questions