Name a Mutex : Mutex : Thread C# Examples


C# Examples » Thread » Mutex »

 

Name a Mutex









    
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(  );
        }
    }
}
    
   
  
   



Output

Have Mutex
Releasing
Have Mutex
Releasing
...
...
^CTerminate batch job (Y/N)? n


HTML code for linking to this page:

Follow Navioo On Twitter

C# Examples

 Navioo Thread
» Mutex