using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace NamedMutexForSingleton
{
class Program
{
static void Main(string[] args)
{
System.Threading.Mutex mut = new System.Threading.Mutex(false, "NamedMutexForSingleton");
if (!mut.WaitOne(3,false))
{
Console.WriteLine("already running one!!!!!!!!!!!");
mut.Close();
}
else
{
Console.WriteLine("this is only running");
}
Console.ReadKey();
}
}
}
Mutex(Boolean, String)
使用 Boolean 值(指示调用线程是否应具有互斥体的初始所有
利用已命名的Mutex对象的进程共享性,可实现跨进程的线程信号通信原理,简单实现程序单实例运行的一种思路
权以及字符串是否为互斥体的名称)初始化 Mutex 类的新实例。