winform防止程序重复运行
修改程序主入口函数:
static class Program
{
/// <summary>
/// 应用程序的主入口点。
/// </summary>
[STAThread]
static void Main()
{
bool isRuned;
System.Threading.Mutex mutex = new System.Threading.Mutex(true, "BC064A223AB84B628D03E73631E55145", out isRuned);
if (isRuned)
{
Application.EnableVisualStyles();
Application.SetCompatibleTextRenderingDefault(false);
Application.Run(new MainForm());
mutex.ReleaseMutex();
}
else
{
MessageBox.Show("程序已启动,请勿重复打开!", "提示", MessageBoxButtons.OK, MessageBoxIcon.Information);
}
}
}

浙公网安备 33010602011771号