473,503 Members | 2,197 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

Quick Mutex Question

dln
If I were to use the following call:

Mutex my_mutex = new Mutex();
bool got_lock = my_mutex.WaitOne(500, false);

and then got_lock returns false, do I need to call "my_mutex.ReleaseMutex()"
on it? So put another way, should I always call ReleaseMutex, regardless of
whether or not I got the lock?

Thanks.
Nov 16 '05 #1
2 971
dln <dn**********@hotmail.com> wrote:
If I were to use the following call:

Mutex my_mutex = new Mutex();
bool got_lock = my_mutex.WaitOne(500, false);

and then got_lock returns false, do I need to call "my_mutex.ReleaseMutex()"
on it? So put another way, should I always call ReleaseMutex, regardless of
whether or not I got the lock?


No - if you didn't acquire it, you shouldn't release it.

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

"Jon Skeet [C# MVP]" <sk***@pobox.com> wrote in message
news:MP************************@msnews.microsoft.c om...
dln <dn**********@hotmail.com> wrote:
If I were to use the following call:

Mutex my_mutex = new Mutex();
bool got_lock = my_mutex.WaitOne(500, false);

and then got_lock returns false, do I need to call "my_mutex.ReleaseMutex()" on it? So put another way, should I always call ReleaseMutex, regardless of whether or not I got the lock?


No - if you didn't acquire it, you shouldn't release it.

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

Nov 16 '05 #3

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

Similar topics

2
989
by: dln | last post by:
If I were to use the following call: Mutex my_mutex = new Mutex(); bool got_lock = my_mutex.WaitOne(500, false); and then got_lock returns false, do I need to call "my_mutex.ReleaseMutex()"...
2
226
by: dln | last post by:
If I were to use the following call: Mutex my_mutex = new Mutex(); bool got_lock = my_mutex.WaitOne(500, false); and then got_lock returns false, do I need to call "my_mutex.ReleaseMutex()"...
16
3131
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
6199
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...
0
7093
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
7287
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
7349
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...
1
7008
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...
1
5022
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new...
0
4688
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and...
0
3168
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
746
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
0
399
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence...

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.