static private bool IsOneInstance()
{
#if !DEBUG
bool one;
mutex = new System.Threading.Mutex(true, "VIPSHOP", out one);
return one;
#else
return true;
#endif
}
if (IsOneInstance())
{
Application.Run(new LoginFrm());
}
else
{
MessageBox.Show("只允许运行一个实例", "系统提示", MessageBoxButtons.OK, MessageBoxIcon.Information);
}
在Application.ApplicationExit += new EventHandler(Application_ApplicationExit);
释放mutex
if (mutex != null)
{
mutex.ReleaseMutex();
mutex.Close();
}