给定以下使用Mutex的代码片段:
对于我的一些用户,在创建Mutex(在catch块中)时,会抛出UnauthorizedAccessException异常。我正在尝试找到引起此异常的原因。
消息是:
访问路径“Global\MyMutex”被拒绝。
我知道一些遇到问题的用户不是他们电脑的管理员。我已经阅读了MSDN关于Mutex和MutexAccessRule的内容,但我不清楚在哪里可以为给定用户分配或查看与Mutex相关的权限。
string mutexName = @"Global\MyMutex";
try
{
_mutex = Mutex.OpenExisting(mutexName, MutexRights.Synchronize);
}
catch (WaitHandleCannotBeOpenedException)
{
SecurityIdentifier securityIdentifier = new SecurityIdentifier(WellKnownSidType.WorldSid, null);
MutexSecurity mutexSecurity = new MutexSecurity();
mutexSecurity.AddAccessRule(new MutexAccessRule(securityIdentifier, MutexRights.Synchronize, AccessControlType.Allow));
bool dummy = false;
// Creates the internal Mutex without taking ownership on it.
_mutex = new Mutex(false, mutexName, out dummy, mutexSecurity);
}
对于我的一些用户,在创建Mutex(在catch块中)时,会抛出UnauthorizedAccessException异常。我正在尝试找到引起此异常的原因。
消息是:
访问路径“Global\MyMutex”被拒绝。
我知道一些遇到问题的用户不是他们电脑的管理员。我已经阅读了MSDN关于Mutex和MutexAccessRule的内容,但我不清楚在哪里可以为给定用户分配或查看与Mutex相关的权限。