public static Process RunningInstance()
{
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 <= 0)
{
process.Kill();
return null;
//return process;
}
}
}
return null;
}
转载于:https://www.cnblogs.com/yi-u/p/7940321.html
最后
以上就是微笑诺言最近收集整理的关于C#检查单个实例的全部内容,更多相关C#检查单个实例内容请搜索靠谱客的其他文章。
发表评论 取消回复