473,503 Members | 1,697 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

Mutex problem

Hi.

I want to use the same mutex in different classes (web pages in an ASP.NET
application). In global.asax.cs, the class that starts up first, I create a
Mutex like this:

static private Mutex mtxBezoeken = new Mutex(false, "bezoeken");

which compiles and executes just fine. Then in another page I want to write
to a file that may also be accessed by global.asax.cs so I want access to
the same mutex that will help me synchronize. In this other page class I
declare another Mutex object with an identical declaration. The idea is that
the system will look up any existing mutex with the id "bezoeken" and wrap
that in the Mutex object instead of creating a new system mutex. This is how
it is documented and what I am used to from Win32 programming.

However, when the second declaration is executed I get:

"System.ApplicationException: Access is denied."

It is obviously because the mutex already exists, when I change "bezoeken"
in the second declaration to a new unique id it executes fine. Of course
this would defeat the purpose of the second mutex.

I am not requesting ownership, I can't figure out what the problem is.

Martin.
Nov 15 '05 #1
2 4760
I assume you are using some sort of impersonation in your ASP.NET
application. When your global.asax.ca routine is called it is called on a
thread with the worker process identity. This creates the mutex with the
default DACL for that identity (probably giving access only to that
identity, the local system and maybe administrators). Later, in your page,
the call to CreateMutex is executed on a thread with another identity that
does not have access to the original mutex so the call fails with an access
denied error.
"Martin Maat" <du***@somewhere.nl> wrote in message
news:10*************@corp.supernews.com...
Hi.

I want to use the same mutex in different classes (web pages in an ASP.NET
application). In global.asax.cs, the class that starts up first, I create a Mutex like this:

static private Mutex mtxBezoeken = new Mutex(false, "bezoeken");

which compiles and executes just fine. Then in another page I want to write to a file that may also be accessed by global.asax.cs so I want access to
the same mutex that will help me synchronize. In this other page class I
declare another Mutex object with an identical declaration. The idea is that the system will look up any existing mutex with the id "bezoeken" and wrap
that in the Mutex object instead of creating a new system mutex. This is how it is documented and what I am used to from Win32 programming.

However, when the second declaration is executed I get:

"System.ApplicationException: Access is denied."

It is obviously because the mutex already exists, when I change "bezoeken"
in the second declaration to a new unique id it executes fine. Of course
this would defeat the purpose of the second mutex.

I am not requesting ownership, I can't figure out what the problem is.

Martin.

Nov 15 '05 #2
"Stephen Martin" <sm*****@removethis.emsoft.andthis.ca> wrote in message
news:OI**************@TK2MSFTNGP12.phx.gbl...
I assume you are using some sort of impersonation in your ASP.NET
application. When your global.asax.ca routine is called it is called on a
thread with the worker process identity. This creates the mutex with the
default DACL for that identity (probably giving access only to that
identity, the local system and maybe administrators). Later, in your page,
the call to CreateMutex is executed on a thread with another identity that
does not have access to the original mutex so the call fails with an access denied error.
That doesn't make sense to me. Mutexes have identity-affinity? I always
considered them to be system-wide objects with the purpose of synchronizing
resource access regardless what thread, process or identity is requesting
it. Isn't that the whole idea?

Anyway, it seems you are right because when I try to do the same thing from
a single page:

static private Mutex mtxBezoeken1 = new Mutex(false, "bezoeken");
static private Mutex mtxBezoeken2 = new Mutex(false, "bezoeken");

it runs just fine.

So the Monitor class is fine if you don't need to go beyond the scope of a
single object, mutexes are fine if you don't need to go beyond the scope of
a single user, ... what do I use to address my little problem here?
Semaphores don't seem to exist in .NET (or would "InterLocked" cover that?).
There is not a lot of stuff on the net about mutexes and user identities.

Thanks for the first part of the solution.

Martin.

"Martin Maat" <du***@somewhere.nl> wrote in message
news:10*************@corp.supernews.com...
Hi.

I want to use the same mutex in different classes (web pages in an ASP.NET application). In global.asax.cs, the class that starts up first, I create
a
Mutex like this:

static private Mutex mtxBezoeken = new Mutex(false, "bezoeken");

which compiles and executes just fine. Then in another page I want to

write
to a file that may also be accessed by global.asax.cs so I want access

to the same mutex that will help me synchronize. In this other page class I
declare another Mutex object with an identical declaration. The idea is

that
the system will look up any existing mutex with the id "bezoeken" and wrap that in the Mutex object instead of creating a new system mutex. This is

how
it is documented and what I am used to from Win32 programming.

However, when the second declaration is executed I get:

"System.ApplicationException: Access is denied."

It is obviously because the mutex already exists, when I change "bezoeken" in the second declaration to a new unique id it executes fine. Of course
this would defeat the purpose of the second mutex.

I am not requesting ownership, I can't figure out what the problem is.

Martin.


Nov 15 '05 #3

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

Similar topics

5
3749
by: Ken Varn | last post by:
I have a named mutex object that is accessed by both an asp.net application and a Windows executable .net application. The Windows executable runs under the administrator logon, while the asp.net...
193
9367
by: Michael B. | last post by:
I was just thinking about this, specifically wondering if there's any features that the C specification currently lacks, and which may be included in some future standardization. Of course, I...
16
3131
by: Ed Sutton | last post by:
I use a mutex to disallow starting a second application instance. This did not work in a release build until I made it static member of my MainForm class. In a debug build, first instance got...
4
1627
by: google | last post by:
Hi Guys, I'm having a bizarre problem here with mutexes. If I have the following code in a page (note that it never releases the mutex!), then load the page twice, in 2 seperate browsers, I do...
1
2047
by: cold80 | last post by:
I'm trying to check in my application if another instance of it is already running. I found many code snippets on the net that make use of a named mutex to do this check, but I can't make it work...
3
4943
by: cold80 | last post by:
I'm trying to check in my application if another instance of it is already running. I found many code snippets on the net that make use of a named mutex to do this check, but I can't make it work...
3
5524
by: NaeiKinDus | last post by:
Hello, i'm trying to program a thread that would be locked (by a mutex) and that would only be unlocked once that a function (generating data) is done. The purpose is to generate data, and unlock...
8
574
by: Dan Pavel | last post by:
Hi, I did not used Mutex before and I need now. I have an application that control some workflows on different machines. I use SNMP for that. The problem is that the thread used for starting an...
11
3667
by: Lamont Sanford | last post by:
Given an object of type Mutex, what method or property should be called to determine if it is currently owned? I could call WaitOne(0,false) -- and if the return value is false, I could deduce...
0
7199
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
7074
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
7273
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
7322
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
0
7451
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
0
5572
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...
0
1501
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated ...
1
731
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
0
374
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence...

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.