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 mutexand exit.");
Console.ReadLine();
mt.ReleaseMutex();
}
} আউটপুট
Waiting for the Mutex. Owner of the mutex. ENTER is to be pressed to release the mutex and exit.