bool createdNew;
System.Threading.Mutex instance = new System.Threading.Mutex(true, "MutexName", out createdNew);
if (createdNew)
{
Application.Run(new LoginForm());
instance.ReleaseMutex();
}
else
{
Application.Exit();
}
还可以写成以下形式,一个窗体只能启动一次
Form1 a = new Form1();
bool createdNew;
System.Threading.Mutex instance = new System.Threading.Mutex(true, "MutexName", out createdNew);
if (createdNew)
{
a.ShowDialog();
instance.ReleaseMutex();
}
else
{
a.Close();
} 猜你喜欢