I am using a global named mutex for file access synchronization between an ASP.NET application and a console application.
While running the ASP.NET application, the console application fails to acquire mutex - as expected. While running the console application, the ASP.NET application throws UnauthorizedAccessException: Access to the path 'Global\TheNameOfTheMutex' is denied.
I will try to catch the exception and treat it like it failed to acquire the mutex, but I want to know why is it behaving like this? The ASP.NET application runs as expected if it is accessed from two different browsers and the console applications also runs as expected when running multiple instances.
Update: on Windows XP the exception is also thrown when the ASP.NET application is running and I try to start the console application.
The code used for synchronization is in a common assembly:
using (Mutex m = new Mutex(false, "Global\\TheNameOfTheMutex")) // exception thrown
{
try
{
lock = m.WaitOne(0, false);
}
catch (AbandonedMutexException)
{
// ...
}
if(lock)
{
// ...
m.ReleaseMutex();
}
}
Environment: Windows Server 2008, IIS 7, ASP.NET 2.0