473,657 Members | 2,430 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.Applica tionException: 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 4770
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***@somewher e.nl> wrote in message
news:10******** *****@corp.supe rnews.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.Applica tionException: 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*****@remove this.emsoft.and this.ca> wrote in message
news:OI******** ******@TK2MSFTN GP12.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 "InterLocke d" 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***@somewher e.nl> wrote in message
news:10******** *****@corp.supe rnews.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.Applica tionException: 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
3788
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 application runs under the standard asp.net user account. The problem relates to permissions on creation of the mutex. If the asp.net application creates the mutex, the executable cannot access it (access denied error). Likewise, if the...
193
9520
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 speak only of features in the spirit of C; something like object-orientation, though a nice feature, does not belong in C. Something like being able to #define a #define would be very handy, though, e.g: #define DECLARE_FOO(bar) #define...
16
3147
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 ownership, second did not and terminated. In a release build, the second instance *also* got ownership. I "fixed" it by making the mutex a static member of my MainForm class. Did the garbage collector eat my mutex because it is not referenced
4
1635
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 not get a mutex lock. Any ideas? I'm trying to get a globally accessible mutex. Is using the Application object wrong somehow?
1
2054
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 on visual basic. Actually, it works sometimes and sometimes not. The code I'm trying is: Namespace WindowsApplication2 Public Class Form1 Inherits Form
3
4951
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 on visual basic. Actually, it works sometimes and sometimes not. The code I'm trying is: Namespace WindowsApplication2 Public Class Form1 Inherits Form
3
5548
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 the mutex in order to activate the thread once the data is generated. I have to do it this way, i can only call the thread if the data are generated. ******************************************************** step 1: initialize the mutex
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 workflow need to write in some OID. When I start 2 workflows on the same machine the second thread need to wait for the first one to finish and after that continue work. This works OK. The problem is when I have to start 2 workflows on different...
11
3682
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 that the Mutex is already owned... but this has the unwanted side effect of seizing ownership of the Mutex in the case where the Mutex is NOT already owned. I'm looking for something like an "IsOwned" property.
0
8392
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, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main usage, and What is the difference between ONU and Router. Let’s take a closer look ! Part I. Meaning of...
0
8305
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 effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
1
8503
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
0
8603
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 protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
0
7320
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, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then launch it, all on its own.... Now, this would greatly impact the work of software developers. The idea...
1
6163
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes instead of User Defined Types (UDT). For example, to manage the data in unbound forms. Adolph will...
0
5632
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert into image. Globals.ThisAddIn.Application.ActiveDocument.Select();...
1
2726
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 we have to send another system
2
1604
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 can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating effective websites that not only look great but also perform exceptionally well. In this comprehensive...

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.