貼在main()中 看需求修改:
int processCount = 0;
Process[] pa = Process.GetProcesses();
foreach (Process PTest in pa)
{
if (PTest.ProcessName ==
Process.GetCurrentProcess().ProcessName)
{
processCount += 1;
}
}
if (processCount > 1)
{
DialogResult dr;
dr = MessageBox.Show(Process.GetCurrentProcess().ProcessName
+ "程式已經執行", "!", MessageBoxButtons.OK, MessageBoxIcon.Error);
return;
}