0

I need to open a window on a new thread, and I'm wondering if I should mark the thread as STA or MTA? I know that threadpool threads run as MTA, but they're typically not associated with any UI elements. Do winforms windows need to run as STA?

Jon Tackabury
  • 47,710
  • 52
  • 130
  • 168
  • 1
    Related: http://stackoverflow.com/questions/4344835/cant-start-winform-from-a-thread. Short answer: Don't do it. A user can only manipulate one form at a time anyway. If you need processes running in the background, you can spin up a thread to do that, or use a `BackgroundWorker` object. – Robert Harvey Feb 21 '12 at 23:19
  • A thread that creates a window *must* be STA. The clipboard, drag+drop and the shell dialogs require STA. – Hans Passant Feb 22 '12 at 01:19

1 Answers1

2

Take a look at the correct answer for this SO question, explains STA vs MTA very well.

I would recommend running it as STA if it is a winforms window regardless, otherwise you will run into undefined behavior territory even if you get it to compile.

Community
  • 1
  • 1
Abdul Hfuda
  • 1,463
  • 12
  • 25