Mutex failing in Release

  • Thread starter Thread starter Guest
  • Start date Start date
G

Guest

Hello,

Encountering a issue where I define a mutex to enforce a single instance of
an application. It works well under Debug but switching to release it fails
everytime..

bool exclusive = false;
Mutex m = new Mutex(true, "SOEIFrameworkMutex", out exclusive);

if (exclusive)
{
// run app
}
else
{
// lookup exisitng process and bring to the fore
}

Any ideas on what could cause this are most appreciated

AC
 
Cavey said:
Encountering a issue where I define a mutex to enforce a single instance of
an application. It works well under Debug but switching to release it fails
everytime..

bool exclusive = false;
Mutex m = new Mutex(true, "SOEIFrameworkMutex", out exclusive);

if (exclusive)
{
// run app
}
else
{
// lookup exisitng process and bring to the fore
}

Any ideas on what could cause this are most appreciated

Your mutex is being garbage collected. Either assign it to a static
variable, or put a "using" statement around the main code:

bool exclusive = false;
using (Mutex = new Mutex(true, "SOEIFrameworkMutex", out exclusive))
{
if (exclusive)
{
// run app
}
else
{
// lookup exisitng process and bring to the fore
}
}
 
Thank You Jon



Jon Skeet said:
Your mutex is being garbage collected. Either assign it to a static
variable, or put a "using" statement around the main code:

bool exclusive = false;
using (Mutex = new Mutex(true, "SOEIFrameworkMutex", out exclusive))
{
if (exclusive)
{
// run app
}
else
{
// lookup exisitng process and bring to the fore
}
}
 
Back
Top