C#检查单个实例
2021-04-24 21:29
标签:static ext sse pat nbsp pdo second run kill public static Process RunningInstance() C#检查单个实例 标签:static ext sse pat nbsp pdo second run kill 原文地址:http://www.cnblogs.com/yi-u/p/7940321.html
{
Process currentProcess = Process.GetCurrentProcess();
Process[] sameProcess = Process.GetProcessesByName(System.IO.Path.GetFileNameWithoutExtension(AppDomain.CurrentDomain.BaseDirectory + currentProcess.ProcessName));
if (sameProcess != null && sameProcess.Length > 0)
{
// 遍历正在有相同名字运行的例程
foreach (Process process in sameProcess)
{
// 忽略现有的例程
if (process.Id != currentProcess.Id && (process.StartTime - currentProcess.StartTime).TotalMilliseconds {
process.Kill();
return null;
//return process;
}
}
}
return null;
}
下一篇:python的垃圾回收机制