473,396 Members | 2,011 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,396 software developers and data experts.

Mutex run ok in debug model,but failed in 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();
}

Nov 22 '05 #1
3 1920
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???
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().

--
Jon Skeet - <sk***@pobox.com>
http://www.pobox.com/~skeet
If replying to the group, please do not mail me too
Nov 22 '05 #2
> > 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().


But disposing it wouldn't let it stay alive, does it?
Nov 22 '05 #3
cody <de********@gmx.de> 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???
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().


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.

--
Jon Skeet - <sk***@pobox.com>
http://www.pobox.com/~skeet
If replying to the group, please do not mail me too
Nov 22 '05 #4

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

0
by: Srijit Kumar Bhadra | last post by:
Hello, Here is some sample code with pywin32 build 203 and ctypes 0.9.6. Best regards, /Srijit File: SharedMemCreate_Mutex_win32all.py # This application should be used with...
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,...
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...
2
by: tony.newsgrps | last post by:
Hi there, I'm trying to understand the impact of killing a process that owns a system mutex (used to ensure there is only 1 instance of my program running) Here is my code pretty much: try...
6
by: Andrew Rowley | last post by:
I am having trouble getting debug and release builds to work properly with project references using C++ .NET and Visual Studio 2003. I created a test solution, with a basic Windows form C++...
2
by: =?Utf-8?B?Q2F2ZXk=?= | last post by:
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 =...
11
by: Lamont Sanford | last post by:
Given an object of type Mutex, what method or property should be called to determine if it is currently owned? I could call WaitOne(0,false) -- and if the return value is false, I could deduce...
45
by: Chris Forone | last post by:
hello group, is there a chance for other functions to get the lock if i have following loop: while (running) { Lock local(mutex); }
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
0
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...

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.