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);
}
複制