如果我在UI上调用方法线程是否被Windows消息队列搜索到,并且随后不需要重新进入?在UI线程上编组的方法是否需要线程安全
private void CalledFromWorkerThread()
{
//changed from 'InvokeRequired' Anti-Pattern
this.Invoke((Action) (() => _counter++; /* Is this ok? */));
}
澄清:只有将访问_counter UI线程。
如果您还没有,还应该在柜台上使用锁定。 – 2011-06-24 13:47:29
另请参见:http://www.yoda.arachsys.com/csharp/threads/winforms.shtml – 2011-06-24 13:51:25
测试'InvokeRequired'是一种反模式。 'Control.Invoke'已经包含这样一个检查。 –