Google Groups no longer supports new Usenet posts or subscriptions. Historical content remains viewable.
Dismiss

C# Mutex usage

5 views
Skip to first unread message

anjna....@gmail.com

unread,
Feb 25, 2015, 9:20:41 PM2/25/15
to
Hi I made following program
using System;
using System.Threading;

namespace mutex
{
class Program
{
static void Main(string[] args)
{
Mutex mutex =null , mutex1 =null;
string mutexName = "test";
try
{
mutex = new Mutex(false /*initiallyOwned*/, mutexName);
mutex.WaitOne(0, false);
mutex1 = new Mutex(false /*initiallyOwned*/, mutexName);
mutex1.WaitOne(0, false);
}
finally
{
Console.WriteLine("released mutex");
Thread.Sleep(30000);
if (null != mutex1) mutex1.ReleaseMutex();

if (null != mutex) mutex.ReleaseMutex();
}

}
}
}

The exe should block after 2nd waitone call as would have locked the mutex till release mutex is called. But it does not stop at 2nd waitone why?
0 new messages