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

Mutex failing in Release

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 = false;
Mutex m = new Mutex(true, "SOEIFrameworkMutex", out exclusive);

if (exclusive)
{
// run app
}
else
{
// lookup exisitng process and bring to the fore
}

Any ideas on what could cause this are most appreciated

AC
May 8 '07 #1
2 1394
Cavey <Ca***@discussions.microsoft.comwrote:
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 = false;
Mutex m = new Mutex(true, "SOEIFrameworkMutex", out exclusive);

if (exclusive)
{
// run app
}
else
{
// lookup exisitng process and bring to the fore
}

Any ideas on what could cause this are most appreciated
Your mutex is being garbage collected. Either assign it to a static
variable, or put a "using" statement around the main code:

bool exclusive = false;
using (Mutex = new Mutex(true, "SOEIFrameworkMutex", out exclusive))
{
if (exclusive)
{
// run app
}
else
{
// lookup exisitng process and bring to the fore
}
}

--
Jon Skeet - <sk***@pobox.com>
http://www.pobox.com/~skeet Blog: http://www.msmvps.com/jon.skeet
If replying to the group, please do not mail me too
May 8 '07 #2
Thank You Jon

"Jon Skeet [C# MVP]" wrote:
Cavey <Ca***@discussions.microsoft.comwrote:
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 = false;
Mutex m = new Mutex(true, "SOEIFrameworkMutex", out exclusive);

if (exclusive)
{
// run app
}
else
{
// lookup exisitng process and bring to the fore
}

Any ideas on what could cause this are most appreciated

Your mutex is being garbage collected. Either assign it to a static
variable, or put a "using" statement around the main code:

bool exclusive = false;
using (Mutex = new Mutex(true, "SOEIFrameworkMutex", out exclusive))
{
if (exclusive)
{
// run app
}
else
{
// lookup exisitng process and bring to the fore
}
}

--
Jon Skeet - <sk***@pobox.com>
http://www.pobox.com/~skeet Blog: http://www.msmvps.com/jon.skeet
If replying to the group, please do not mail me too
May 8 '07 #3

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

Similar topics

1
by: Didier FRAISSE | last post by:
i want to be sure that only one instance of my script is running at the same time i try this little script #--------------------------------------------------------------------------- # -*-...
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...
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,...
2
by: Lowell | last post by:
I want a (global) mutex which prevents a section of my code from being run by more than one process (or user) at a time. I have something that works, EXCEPT when there is an exception of some kind. ...
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...
16
by: mfdatsw1 | last post by:
I need to be certain my application only runs once on a machine, and I implemented a solution using Mutex. The solution was posted many times, but one great link I found is...
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...
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: taylorcarr | last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: aa123db | last post by:
Variable and constants Use var or let for variables and const fror constants. Var foo ='bar'; Let foo ='bar';const baz ='bar'; Functions function $name$ ($parameters$) { } ...
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
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
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
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...

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.