111,131
社区成员
发帖
与我相关
我的任务
分享
[STAThread]
static void Main()
{
bool bExist;
//使用指示调用线程是否应拥有互斥体的初始所属权的布尔值、作为互斥体名称的字符串以及在方法返回时指示调用线程是否已被授予互斥体的初始所属权的布尔值来初始化 Mutex 类的新实例。
Mutex MyMutex = new Mutex(true, "test", out bExist);
if (bExist)
{
Application.EnableVisualStyles();
Application.SetCompatibleTextRenderingDefault(false);
Application.Run(new MainForm());
MyMutex.ReleaseMutex();
}
else
{
MessageBox.Show("程序已经运行", "信息提示", MessageBoxButtons.OK, MessageBoxIcon.Information);
}
}