473,320 Members | 1,990 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,320 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
semaphoreSecurity)
at Common.InterProcessReaderWriterLock..ctor(String name, Int32
maxLocks) in InterProcessReaderWriterLock.cs: 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.
Jun 27 '08 #1
0 2206

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

7
by: Bastian Hammer | last post by:
Hi I´m wondering why there are so few examples with Semaphore. Is it obsolete? I´ve got a Class Data. It offers 2 Threads methods for updating, editing, .. a private dictionary. Now I...
4
by: Ron Vecchi | last post by:
I a runnning w2k3 pop3 mail server that came with iis6. I would like to write an application that progammtically creates the new mailboxes in an already established mail domain. Does anyone know...
6
by: Chad Crowder | last post by:
Getting the following error on my production server whether the file exists or not: "System.IO.IOException: Cannot create a file when that file already exists." Here's the code generating the...
4
by: Martin | last post by:
Hi, I am getting an "Access Denied" error when attempting to browse asp.net pages. I have installed ASP.NET 1.1.4322 on a domain controller. The machine also has ASP.NET 1.0.3705 installed on...
0
by: Torsten Valentin | last post by:
Hi! I have to write a program that should create a new directory ("c:\test") and share that directory with read-access for everyone and read-write-access for administrators. How do I do that in...
0
by: Torsten Valentin | last post by:
Hi! I am working on a program that should create a new directory ("c:\test") and share that directory with read-access for everyone and read-write-access for administrators. How do I do that in...
24
by: Lauren Wilson | last post by:
OK, I'm confused. SOME folks here seem to be saying it IS possible to link to or otherwise access and manipulate MDB files stored on a web server (from the client) and others seem to be saying...
0
by: y2ktan | last post by:
Hi everyone, I had a windows application that written using semaphore and I want to convert it into WinCE. However, I found that in Compact Framework 2.0 SP2 does not contain semaphore class in...
5
by: GHUM | last post by:
hello, in my application I am using hSem = win32event.CreateSemaphore (None, 1, 1,"stringincludinginterfaceandport") rt=win32event.WaitForSingleObject (hSem, 0) if rt !=...
0
by: DolphinDB | last post by:
The formulas of 101 quantitative trading alphas used by WorldQuant were presented in the paper 101 Formulaic Alphas. However, some formulas are complex, leading to challenges in calculation. Take...
0
by: DolphinDB | last post by:
Tired of spending countless mintues downsampling your data? Look no further! In this article, you’ll learn how to efficiently downsample 6.48 billion high-frequency records to 61 million...
0
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, we are pleased to welcome back...
1
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, we are pleased to welcome back...
0
by: Vimpel783 | last post by:
Hello! Guys, I found this code on the Internet, but I need to modify it a little. It works well, the problem is this: Data is sent from only one cell, in this case B5, but it is necessary that data...
0
by: jfyes | last post by:
As a hardware engineer, after seeing that CEIWEI recently released a new tool for Modbus RTU Over TCP/UDP filtering and monitoring, I actively went to its official website to take a look. It turned...
0
by: ArrayDB | last post by:
The error message I've encountered is; ERROR:root:Error generating model response: exception: access violation writing 0x0000000000005140, which seems to be indicative of an access violation...
1
by: PapaRatzi | last post by:
Hello, I am teaching myself MS Access forms design and Visual Basic. I've created a table to capture a list of Top 30 singles and forms to capture new entries. The final step is a form (unbound)...
0
by: af34tf | last post by:
Hi Guys, I have a domain whose name is BytesLimited.com, and I want to sell it. Does anyone know about platforms that allow me to list my domain in auction for free. Thank you

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.