public static Mutex mutex { get; set; }
public static bool InitialOwnership { get; set; }
public static void Main(string[] args)
InitialOwnership = false;
mutex = new Mutex(InitialOwnership);
for (int i = 0; i < threadCount; i++)
var thread = new Thread(new ThreadStart(RunTask));
thread.Name = "Thread #" + (i + 1);
static void ThreadProcess()
Console.WriteLine("{0} thread is trying to access the Mutex.", Thread.CurrentThread.Name);
Console.WriteLine("{0} thread acquired the mutex, and is now processing.", Thread.CurrentThread.Name);
Console.WriteLine("{0} thread is now exiting and freeing the mutex.", Thread.CurrentThread.Name);
Console.WriteLine("{0} thread has freed the mutex.", Thread.CurrentThread.Name);