Mutex run ok in debug model,but failed in release model

  • Thread starter Thread starter Guest
  • Start date Start date
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();
}
 
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???
bool flgDouble ;
Mutex m = new Mutex( true, "App", out flgDouble);
if(flgDouble)
{
//Run Application
RunApp();
}

Chances are it's being garbage collected. Either stick it in a "using"
statement, or use a GC.KeepAlive(m); statement after your RunApp().
 
I use this code to ensure only one application is running at one time.
Chances are it's being garbage collected. Either stick it in a "using"
statement, or use a GC.KeepAlive(m); statement after your RunApp().

But disposing it wouldn't let it stay alive, does it?
 
cody said:
But disposing it wouldn't let it stay alive, does it?

If you put the whole thing in a using statement, including the RunApp
part, then the Dispose call wouldn't happen until after the app had
run. Sorry if I wasn't clear.
 
Back
Top