Mutex is different in debug model and release model?

G

Guest

I use this code to ensure only one application is running at one time.
In debug version, it runs ok
But, in release version, it failed. I don't why???
bool flgDouble ;
Mutex m = new Mutex( true, "App", out flgDouble);
if(flgDouble)
{
//Run Application
RunApp();
}
 
P

Pieter Philippaerts

Napo said:
I use this code to ensure only one application is running at one time.
In debug version, it runs ok
But, in release version, it failed. I don't why???

In my little test project everything worked fine, debug and release builds.

I think the reason you're seeing this error is because the Mutex object is
GCed in the release version before the application is finished. To avoid
this, you should keep a reference to the Mutex until your application exits.
To do this, you could modify your code like this:

bool flgDouble;
Mutex m = new Mutex( true, "App", out flgDouble);
if(flgDouble) {
RunApp();
}
GC.KeepAlive(m);

Regards,
Pieter Philippaerts
 
G

Guest

thanks


Pieter Philippaerts said:
In my little test project everything worked fine, debug and release builds.

I think the reason you're seeing this error is because the Mutex object is
GCed in the release version before the application is finished. To avoid
this, you should keep a reference to the Mutex until your application exits.
To do this, you could modify your code like this:

bool flgDouble;
Mutex m = new Mutex( true, "App", out flgDouble);
if(flgDouble) {
RunApp();
}
GC.KeepAlive(m);

Regards,
Pieter Philippaerts
 

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