471,338 Members | 1,133 Online
Bytes | Software Development & Data Engineering Community
Post +

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 471,338 software developers and data experts.

Mutex is different in debug model and release model?

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();
}

Jul 21 '05 #1
2 1827
"Napo" <Na**@discussions.microsoft.com> wrote
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
Jul 21 '05 #2
thanks
"Pieter Philippaerts" wrote:
"Napo" <Na**@discussions.microsoft.com> wrote
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

Jul 21 '05 #3

This discussion thread is closed

Replies have been disabled for this discussion.

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.