Start If the Mutex does not exist, it creates a new one. Further instances of the program then can tell that an instance is already open.
Info The program incurs one exception in the common case of the first instance being run. Exceptions are slower than many constructs.
But If your program is computationally intensive, it is more beneficial to avoid extra instances.
static Mutex _m;
static bool IsSingleInstance()
// Try to open existing mutex.
// If exception occurred, there is no such mutex.
Program._m = new Mutex(true, "PERL");
// Only one instance.
// More than one instance.
static void Main()
Console.WriteLine("More than one instance"); // Exit program.
Console.WriteLine("One instance"); // Continue with program.
// Stay open.
}1. First execution will display "One instance"
2. Second execution will display "More than one instance"
3. Third execution is the same as second.
Discussion. We can call Release on a Mutex instance once we are done with it. In the example this is not necessary—the Mutex will be released when the program exits.
Info The WaitOne method blocks the current thread until the Mutex has been released.
And We can call the Release() method to release the Mutex. This can help reduce problems with locking.
A summary. The Mutex type provides a way to use system-wide synchronization. It can also synchronize threads within a single program.
When a Mutex has a string name, it can be opened from other processes with OpenExisting. This behavior can be used to enforce synchronization between processes and threads.