471,313 Members | 1,961 Online
Bytes | Software Development & Data Engineering Community
Post +

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 471,313 software developers and data experts.

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(maxLocks, 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 UnauthorizedAccessException. So I tried specifying that
everyone has read rights:
var sec = new SemaphoreSecurity();
sec.AddAccessRule(new SemaphoreAccessRule("Everyone",
SemaphoreRights.ReadPermissions, AccessControlType.Allow));

bool createdNew;

semaphore = new Semaphore(maxLocks, 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.UnauthorizedAccessException: Access to the port is denied.
at System.IO.Ports.InternalResources.WinIOError(Int32 errorCode,
String str)
at System.Threading.Semaphore..ctor(Int32 initialCount, Int32
maximumCount, String name, ref Boolean createdNew, SemaphoreSecurity
at Common.InterProcessReaderWriterLock..ctor(String name, Int32
maxLocks) in InterProcessReaderWriterLock.cs: line 39

Any help would be appreciated.



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.
Jun 27 '08 #1
0 2027

This discussion thread is closed

Replies have been disabled for this discussion.

Similar topics

7 posts views Thread by Bastian Hammer | last post: by
4 posts views Thread by Ron Vecchi | last post: by
4 posts views Thread by Martin | last post: by
reply views Thread by Torsten Valentin | last post: by
reply views Thread by Torsten Valentin | last post: by
5 posts views Thread by GHUM | last post: by

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.