Mutex failing in Release

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
 
J

Jon Skeet [C# MVP]

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
}
}
 
G

Guest

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
}
}
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top