为什么以下结构会导致AbandonedMutexException.即使有错误或方法返回.互斥体正在被释放.
static Mutex WriteMutex = new Mutex(false, @"Global\mutex2203");
public static void Demo()
{
try
{
WriteMutex.WaitOne();
//rest of coding stuff here
}
finally
{
WriteMutex.ReleaseMutex();
}
}
Run Code Online (Sandbox Code Playgroud)
接收报告无法重新生成错误.
编辑:WriteMutex.WaitOne();没有其他代码发生异常.只有这种方法才能触及互斥锁.