測試函數:

private bool AppAlreadyRunning()


...{

System.Diagnostics.Process curProcess = System.Diagnostics.Process.GetCurrentProcess();

System.Diagnostics.Process[] allProcess = System.Diagnostics.Process.GetProcesses();

foreach (System.Diagnostics.Process process in allProcess)


...{

if (process.Id != curProcess.Id)


...{

if (process.ProcessName == curProcess.ProcessName)

return true;

}

}

return false;

}
應用程序中直接判斷:

System.Diagnostics.Process[] pros =

System.Diagnostics.Process.GetProcessesByName(

System.Diagnostics.Process.GetCurrentProcess().ProcessName);

if (pros.Length > 1)


...{

Application.Exit();

return;

}
在此向提供代碼參照的同行表示感謝!