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 老师送的祝福语简短
13 生日祝福语大全女生简短
14 祝女性生日祝福语简短
15 牛年女神节祝福语简短
16 情人表白祝福语简短大气
17 老公开业祝福语简短
18 官宣新年祝福语简短