我在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