I have 2 processes running. Both are creating a named mutex with the code
Mutex mut = new Mutex(false, "ABC");
then both the process use mut.WaitOne()
and mut.ReleaseMutex()
to access a shared database file, a number of times in different methods.
This code runs without any problems on XP.
On Vista, I just try to run one process (Process 1) and create the mutex using the same code.
On the line mut.WaitOne()
, Process 1 goes to sleep permanently.
Notice, by this time I have not even started Process 2.
mut.WaitOne()
is being called in a method (methodX).
methodX is called in a loop from another method (methodY).
The structure of methodX is
try
{
mut.WaitOne();
//do work on the db file
}
catch
{
}
finally
{
try
{
mut.ReleaseMutex();
}
catch
{
}
}
Also methodY and methodX are both working in a BackgroundWorker. While the code to initialize mutex was called in the main application. But, main application never owns the mutex.
Edit
Here is the code:
string mutexName = @"Global\OneComClientDb";
bool mutexWasCreated;
MutexSecurity mSec = new MutexSecurity();
MutexAccessRule rule = new MutexAccessRule(
new SecurityIdentifier(WellKnownSidType.WorldSid, null),
MutexRights.FullControl,
AccessControlType.Allow);
mSec.AddAccessRule(rule);
mut = new Mutex(false, mutexName, out mutexWasCreated, mSec);