new Mutex

image_pdfimage_print
   
 


using System;
using System.Threading;


class NETMutex {
    static Mutex myMutex;

    public static void Main() {
        myMutex = new Mutex(true, "AAA");
        NETMutex nm = new NETMutex();
        Thread t = new Thread(new ThreadStart(nm.Run));
        t.Start();
        Thread.Sleep(5000);
        myMutex.ReleaseMutex();
        myMutex.WaitOne();
    }

    public void Run() {
        Console.WriteLine("In Run");
        myMutex.WaitOne();
        Console.WriteLine("Thread sleeping for 10 secs");
        Thread.Sleep(10000);
        Console.WriteLine("End of Run() method");
    }
}

    


This entry was posted in Thread. Bookmark the permalink.