我已将变量定义为 ThreadStatic:
public static class MyApplicationContext {
[ThreadStatic]
public static bool Monitoring;
}
现在,我应该从 MainThread (已启动新线程)设置变量 Monitoring:
this.syncThread = new Thread(this.InternalWork);
this.syncThread.SetApartmentState(ApartmentState.STA);
this.syncThread.Start();
// now, I should access MyApplicationContext.Monitoring of syncThread.
有没有办法做到这一点?