C# में Mutex क्लास एक सिंक्रनाइज़ेशन प्रिमिटिव है जिसका उपयोग इंटरप्रोसेस सिंक्रनाइज़ेशन के लिए भी किया जा सकता है।
आइए देखें कि एक नया Mutex कैसे बनाएं।
private static Mutex m = new Mutex();
आइए अब देखें कि Mutex क्लास के नए इंस्टेंस को बूलियन मान के साथ कैसे इनिशियलाइज़ करें।
private static Mutex m = new Mutex(true);
अब आइए देखें कि Mutex क्लास के नए इंस्टेंस को बूलियन मान और Mutex के नाम के साथ कैसे इनिशियलाइज़ करें।
उदाहरण
using System;
using System.Threading;
public class Demo {
public static void Main() {
Mutex mt = new Mutex(false, "NewMutex");
Console.WriteLine("Waiting for the Mutex.");
mt.WaitOne();
Console.WriteLine("Owner of the mutex. " + "ENTER is to be pressed to release the mutex and exit.");
Console.ReadLine();
mt.ReleaseMutex();
}
}
आउटपुट
Waiting for the Mutex. Owner of the mutex. ENTER is to be pressed to release the mutex and exit.