Own a Mutex : Mutex : Thread C# Examples


C# Examples » Thread » Mutex »

 

Own a Mutex









    
using  System;
using  System.Threading;

class  MainClass
{
        public  static  void  Main()
        {
                bool  ownsMutex;

                using  (Mutex  mutex  =new  Mutex(true,  "MutexExample",  out  ownsMutex))
                {
                        if  (ownsMutex)
                        {
                                Console.WriteLine("Owned");
                                mutex.ReleaseMutex();
                        }
                        else
                        {
                                Console.WriteLine("Another  instance  of  this  application  "  +
                                        "  already  owns  the  mutex  named  MutexExample.");
                        }
                }
        }
}
    
   
  
   



Output

Owned


HTML code for linking to this page:

Follow Navioo On Twitter

C# Examples

 Navioo Thread
» Mutex