方法一:
[STAThread]
static void Main() { bool isAppRunning = false;
System.Threading.Mutex mutex = new System.Threading.Mutex(
true,
System.Diagnostics.Process.GetCurrentProcess().ProcessName,
out isAppRunning);
if (!isAppRunning)
{
MessageBox.Show("本程序已经在运行了,请不要重复运行!");
Environment.Exit(1);
}
else
{
Application.EnableVisualStyles();
Application.SetCompatibleTextRenderingDefault(false);
Application.Run(new Form1());
}
}
注:也可以这样设置Mutex , Mutex MyMutex = new Mutex(true, "OnlyRunOncetime", out bExist);
确保唯一。
[STAThread]
static void Main() { bool isAppRunning = false;
System.Threading.Mutex mutex = new System.Threading.Mutex(
true,
System.Diagnostics.Process.GetCurrentProcess().ProcessName,
out isAppRunning);
if (!isAppRunning)
{
MessageBox.Show("本程序已经在运行了,请不要重复运行!");
Environment.Exit(1);
}
else
{
Application.EnableVisualStyles();
Application.SetCompatibleTextRenderingDefault(false);
Application.Run(new Form1());
}
}
注:也可以这样设置Mutex , Mutex MyMutex = new Mutex(true, "OnlyRunOncetime", out bExist);
确保唯一。