Threading with Mutex : Mutex « Thread « C# / CSharp Tutorial






using System;
using System.Collections;
using System.Threading;

class MainClass 
{
  public static ArrayList MyList = new ArrayList();

  private static Mutex MyMutex = new Mutex(false, "MyMutex");

  static void Main(string[] args)
  {
      Thread ThreadOne = new Thread(new ThreadStart(MutexExample));
    ThreadOne.Start();
  }
  protected static void MutexExample()
  {
    MyMutex.WaitOne();
    MyList.Add(" a value");
    MyMutex.ReleaseMutex();
  }
}








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