Name a Mutex : Mutex « Thread « C# / CSharp Tutorial






using System;
using System.Threading;

class MainClass {


  public static void Main( string[] args ) {

    string mutexName = "MainClass";

    Mutex m = new Mutex( false, mutexName );

    for( ;; ) {
      m.WaitOne( );
      Console.WriteLine("Have Mutex");
      Console.WriteLine("Releasing");
      m.ReleaseMutex( );
    }
  }
}
Have Mutex
Releasing
Have Mutex
Releasing
...
...
^CTerminate batch job (Y/N)? n








20.20.Mutex
20.20.1.Threading with Mutex
20.20.2.Use a Mutex to control a shared resource against two current threads
20.20.3.Use the Mutex object: WaitOne
20.20.4.Own a Mutex
20.20.5.Name a Mutex
20.20.6.How a Mutex is used to synchronize access to a protected resource