使用Semaphore的UnauthorizedAccessException

时间:2013-02-18 15:17:10

标签: c# semaphore

我正在创建一个信号量:

System.Security.Principal.SecurityIdentifier sid = new System.Security.Principal.SecurityIdentifier(System.Security.Principal.WellKnownSidType.WorldSid, null);
try
{
    bool createdNew;
    System.Security.AccessControl.SemaphoreSecurity semaphoreSecurity = new System.Security.AccessControl.SemaphoreSecurity();
    semaphoreSecurity.SetAccessRule(new System.Security.AccessControl.SemaphoreAccessRule(sid, System.Security.AccessControl.SemaphoreRights.FullControl, System.Security.AccessControl.AccessControlType.Allow));
    this.semaphore = new Semaphore(1, 1, semaphoreName, out createdNew, semaphoreSecurity);
    if (!this.semaphore.WaitOne(timeoutInMilliSeconds))
        throw new TimeoutException("Timeout while waiting " + semaphoreName + " semaphore (" + timeoutInMilliSeconds + " ms)");
}
catch (System.UnauthorizedAccessException e)
{
    this.semaphore = null;
    throw new UnauthorizedAccessException("Semaphore '" + semaphoreName + "'. " + e.Message);
}
catch
{
    this.semaphore = null;
    throw;
}

在Semaphore构造函数中出现UnauthorizedAccessException并显示下一条消息:

  

信号量'Global \ Program.Req.Sem'。访问该端口被拒绝“

怎么了?如何解决?

其他信息:我想这只适用于非管理员用户,即使他们是“管理员”组的成员。

0 个答案:

没有答案