Acquire the Mutex - CSharp Thread Asynchronous

CSharp examples for Thread Asynchronous:Mutex

Description

Acquire the Mutex

Demo Code

using System;/*from   ww  w  .  ja va  2s . c o  m*/
using System.Threading;
class Application {
   public static void Main( string[] args ) {
      string mutexName = args[0];
      Mutex m = new Mutex( false, mutexName );
      for( ;; ) {
         m.WaitOne( );
         Console.WriteLine("Have Mutex. Press Enter to release");
         Console.ReadLine( );
         Console.WriteLine("Releasing");
         m.ReleaseMutex( );
      }
   }
}

Result


Related Tutorials