title: C# mutex - error calling from ASP.NET and console application
body: <p>I am using a global named mutex for file access synchronization between an ASP.NET application and a console application.</p>
  
  <p>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 <code>UnauthorizedAccessException: Access to the path 'Global\TheNameOfTheMutex' is denied.</code> </p>
  
  <p>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.</p>
  
  <p><strong>Update:</strong> on Windows XP the exception is also thrown when the ASP.NET application is running and I try to start the console application.</p>
  
  <p>The code used for synchronization is in a common assembly:</p>
  
  <pre><code>using (Mutex m = new Mutex(false, "Global\\TheNameOfTheMutex")) // exception thrown
  {
    try
    {
      lock = m.WaitOne(0, false);
    }
    catch (AbandonedMutexException)
    {
      // ...
    }
  
    if(lock)
    {
      // ...
  
      m.ReleaseMutex();
    }
  }
  </code></pre>
  
  <p>Environment: Windows Server 2008, IIS 7, ASP.NET 2.0</p>