Process[] processes = Process.GetProcessesByName(Process.GetCurrentProcess().ProcessName); // no ".exe"
if (processes.Length > 1)
{
log.Fatal("Another instance is running.");
Environment.Exit(1);
}
复制
如果想自动关闭窗口,只需要更改为:
Process[] processes = Process.GetProcessesByName(Process.GetCurrentProcess().ProcessName); // no ".exe"
if (processes.Length > 1)
{
log.Fatal("Another instance is running.");
Environment.Exit(0);
}
复制