3
我很想知道何时在C#.net中使用STA/MTA?什么时候应该将一个线程设置为ApartmentState.STA?
using (ManualResetEventSlim mre = new ManualResetEventSlim(false))
{
Thread _STAThread = new Thread(new ThreadStart(() =>
{
globalComObject = new ComClass();
mre.Set();
try
{
Thread.CurrentThread.Join();
}
catch (ThreadAbortException)
{ }
}));
_STAThread.SetApartmentState(ApartmentState.STA);
_STAThread.IsBackground = true;
_STAThread.Start();
mre.Wait();
}
**参见**: http://stackoverflow.com/questions/127188/could-you-explain-sta-and-mta – pjvds