如何检查当前线程的公寓状态?

sti*_*k81 24 .net c# multithreading sta apartment-state

我有一个需要在STA公寓状态下运行的功能.我不想检查它是否作为STA运行,如果没有生成一个在STA中运行的新线程.

如何检查当前线程运行的公寓状态?

Mar*_*rek 31

System.Threading.Thread.CurrentThread.GetApartmentState()
Run Code Online (Sandbox Code Playgroud)


M.A*_*nin 5

在函数内使用此方法或类似方法:

System.Threading.Thread.CurrentThread.GetApartmentState
Run Code Online (Sandbox Code Playgroud)