new Mutex(true, “MutexExample”, out ownsMutex)), ReleaseMutex

image_pdfimage_print
   
 

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.ReadLine();
                mutex.ReleaseMutex();
            } else {
                Console.WriteLine("Another instance of this application " +
                    " already owns the mutex named MutexExample.");
            }
        }
    }
}

    


This entry was posted in Thread. Bookmark the permalink.