C#中的Mutex类是什么?
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("等待互斥。");
mt.WaitOne();
Console.WriteLine("Owner of the mutex. " + "ENTER is to be pressed to release the mutexand exit.");
Console.ReadLine();
mt.ReleaseMutex();
}
}输出结果
等待互斥。 Owner of the mutex. ENTER is to be pressed to release the mutex and exit.
热门推荐
10 病人祝福语老师寄语简短
11 新娘生孩子祝福语简短
12 婆婆66岁祝福语简短
13 今天孩子高考祝福语简短
14 送彩票生日祝福语简短
15 分别祝福语简短情话英文
16 画室揭牌仪式祝福语简短
17 女友妈妈生日祝福语简短
18 离别赠言离职祝福语简短