internal static class Program
{
private static Mutex mutex = null;
[STAThread]
static void Main()
{
bool createdNew;
//ZWJAPP是您应用程序的唯一标识
mutex = new Mutex(true, "ZWJAPP", out createdNew);
if (createdNew)
{
Application.EnableVisualStyles();
Application.SetCompatibleTextRenderingDefault(false);
Application.Run(new Form1()); // 在应用程序退出时释放互斥体
mutex.ReleaseMutex();
}
else
{
MessageBox.Show("应用程序已运行,请查看程序右下角运行图标!");
// 已有实例在运行,退出
Application.Exit();
}
}
}