Create a semaphore and specify access rights to everyone?

Collapse
This topic is closed.
X
X
 
  • Time
  • Show
Clear All
new posts
  • Samuel R. Neff

    Create a semaphore and specify access rights to everyone?


    I'm having trouble creating a Semaphore with read-access rights for
    everyone. Originally I was trying to use this code:

    semaphore = new Semaphore(maxLo cks, maxLocks, "RwLock#" + name);

    but when using that code to create a Semaphore instance for an
    existing system semaphore (i.e., the second time the code gets hit), I
    get an UnauthorizedAcc essException. So I tried specifying that
    everyone has read rights:


    var sec = new SemaphoreSecuri ty();
    sec.AddAccessRu le(new SemaphoreAccess Rule("Everyone" ,
    SemaphoreRights .ReadPermission s, AccessControlTy pe.Allow));

    bool createdNew;

    semaphore = new Semaphore(maxLo cks, maxLocks, "RwLock#" + name, out
    createdNew, sec);


    But I still get the same error.

    The error occurs when running unit tests and happens even when
    creating the Semaphore twice in the same process with the same user.
    I'm only creating the Semaphore in .NET from this one application.

    The full error is

    System.Unauthor izedAccessExcep tion: Access to the port is denied.
    at System.IO.Ports .InternalResour ces.WinIOError( Int32 errorCode,
    String str)
    at System.Threadin g.Semaphore..ct or(Int32 initialCount, Int32
    maximumCount, String name, ref Boolean createdNew, SemaphoreSecuri ty
    semaphoreSecuri ty)
    at Common.InterPro cessReaderWrite rLock..ctor(Str ing name, Int32
    maxLocks) in InterProcessRea derWriterLock.c s: line 39

    Any help would be appreciated.

    Thanks,

    Sam




    ------------------------------------------------------------
    We're hiring! B-Line Medical is seeking .NET
    Developers for exciting positions in medical product
    development in MD/DC. Work with a variety of technologies
    in a relaxed team environment. See ads on Dice.com.
Working...