473,231 Members | 2,024 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,231 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 1973
"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 thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

3
by: Napo | last post by:
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,...
16
by: Ed Sutton | last post by:
I use a mutex to disallow starting a second application instance. This did not work in a release build until I made it static member of my MainForm class. In a debug build, first instance got...
3
by: Napo | last post by:
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,...
2
by: Napo | last post by:
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,...
0
by: VivesProcSPL | last post by:
Obviously, one of the original purposes of SQL is to make data query processing easy. The language uses many English-like terms and syntax in an effort to make it easy to learn, particularly for...
3
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 3 Jan 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). For other local times, please check World Time Buddy In...
0
by: abbasky | last post by:
### Vandf component communication method one: data sharing ​ Vandf components can achieve data exchange through data sharing, state sharing, events, and other methods. Vandf's data exchange method...
2
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 7 Feb 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:30 (7.30PM). In this month's session, the creator of the excellent VBE...
0
by: fareedcanada | last post by:
Hello I am trying to split number on their count. suppose i have 121314151617 (12cnt) then number should be split like 12,13,14,15,16,17 and if 11314151617 (11cnt) then should be split like...
0
by: stefan129 | last post by:
Hey forum members, I'm exploring options for SSL certificates for multiple domains. Has anyone had experience with multi-domain SSL certificates? Any recommendations on reliable providers or specific...
0
by: DolphinDB | last post by:
The formulas of 101 quantitative trading alphas used by WorldQuant were presented in the paper 101 Formulaic Alphas. However, some formulas are complex, leading to challenges in calculation. Take...
0
by: Aftab Ahmad | last post by:
Hello Experts! I have written a code in MS Access for a cmd called "WhatsApp Message" to open WhatsApp using that very code but the problem is that it gives a popup message everytime I clicked on...
0
by: Aftab Ahmad | last post by:
So, I have written a code for a cmd called "Send WhatsApp Message" to open and send WhatsApp messaage. The code is given below. Dim IE As Object Set IE =...

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.