How to check apartment state of current thread?

6.9k Views Asked by At

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?

2

There are 2 best solutions below

0
On BEST ANSWER
System.Threading.Thread.CurrentThread.GetApartmentState()
0
On

Use this or a similar method inside the function:

System.Threading.Thread.CurrentThread.GetApartmentState