版权声明:本文为博主原创文章,未经博主允许不得转载。 https://blog.csdn.net/wqq1027/article/details/80939903
/// <summary>
/// 检测进程,只能启动一个
/// </summary>
static void CheckProcess()
{
Process currentProcess = Process.GetCurrentProcess();
foreach (Process item in Process.GetProcessesByName(currentProcess.ProcessName))
{
if (item.Id != currentProcess.Id &&
(item.StartTime - currentProcess.StartTime).TotalMilliseconds <= 0)
{
item.Kill();
item.WaitForExit();
break;
}
}
}