我在ManualResetEvent的一个实例上调用Set方法,偶尔会发生死锁。我在文档中找不到任何内容来表明这是一种阻止方法。什么可能导致MRE。阻塞?什么可能导致EventWaitHandle.Set()阻塞当前线程?
堆栈跟踪:
[Managed to Native Transition]
mscorlib.dll!System.Threading.EventWaitHandle.Set() + 0xe bytes
MyCode.StopAll(bool force) Line 179 + 0xd bytes
MyCode.CalcCheckThread() Line 250 + 0xb bytes
mscorlib.dll!System.Threading.ThreadHelper.ThreadStart_Context(object state) + 0x66 bytes
mscorlib.dll!System.Threading.ExecutionContext.Run(System.Threading.ExecutionContext executionContext, System.Threading.ContextCallback callback, object state) + 0x6f bytes
mscorlib.dll!System.Threading.ThreadHelper.ThreadStart() + 0x44 bytes
private static void StopAll(bool force)
{
if(!force)
LogHelper.SendAllCloseState(logger);
_forcablyExit = force;
_running = false;
_stopWait.Set(); // This line appears to be blocking
}
代码是什么样的? – MoonKnight 2012-03-09 17:28:47
我添加了调用Set()的方法。我还没有在其他线程的堆栈轨迹中找到模式。 – chilltemp 2012-03-09 17:33:29
这很奇怪,因为我从来没有听说过/经历过'MRE.Set'来阻止。你有没有试过在调用之后放置一个'Console.WriteLine'或者其他的输出来确保它没有返回? – Tudor 2012-03-09 17:37:52