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 2026新年祝福语简短语
15 结业蛋糕男生祝福语简短
16 周二祝福语大全简短
17 兔年祝福语简短100字
18 年底拜年祝福语大全简短