在程序运行结束时释放互斥对象,然后执行重启。
static string mutexFlagStr = "TEST1";
static public bool requestRestart = false;
static void Main()
{
Ap***cation.EnableVisualStyles();
Ap***cation.SetCompatibleTextRenderingDefault(false);
// 通过互斥来防止程序多重启动
bool blnCreate;
Mutex m = new Mutex(true, mutexFlagStr, out blnCreate);
if (blnCreate)
{
Ap***cation.Run(new FormMain());
m.***easeMutex();
m.Close();
if (requestRestart)
{
Ap***cation.Restart();
}
}
else
{
Me***geBox.Show("程序已经启动,不能再次启动!");
Ap***cation.Exit();
}
}
在执行重启时,先将requestRestart 赋值为true,然后执行Ap***cation.Exit();
-
上一篇: C#中索引符的理解
下一篇: asp.net的常用代码