27

I have a function which requires to be run in STA apartment state. I wan't to check if it is being run as STA, and if not spawn a new thread which runs in STA.

How can I check which apartment state the current thread is being run in?

M.A. Hanin
  • 8,044
  • 33
  • 51
stiank81
  • 25,418
  • 43
  • 131
  • 202

2 Answers2

36
System.Threading.Thread.CurrentThread.GetApartmentState()
ytoledano
  • 3,003
  • 2
  • 24
  • 39
Marek
  • 10,307
  • 8
  • 70
  • 106
6

Use this or a similar method inside the function:

System.Threading.Thread.CurrentThread.GetApartmentState
M.A. Hanin
  • 8,044
  • 33
  • 51