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






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.");
            }
        }
    }
}
Owned








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