c# exe程序只让启动一个

保证程序在系统中只能启动一个, 

实现思路 : 在程序启动时, 检测系统中所有进程, 判断系统中是否已经存在该程序的进程

在Main函数中添加如下代码 

Process[] pro1 = Process.GetProcessesByName(Process.GetCurrentProcess().ProcessName);
Process[] pro2 = Process.GetProcessesByName("MyProject");
if (pro1.Length > 1 || pro2.Length > 1)
{
     MessageBox.Show("目前已有一个安装程序在运行,请勿重复运行程序!", "提示", MessageBoxButton.OK, MessageBoxImage.Warning);
     System.Windows.Application.Current.Shutdown();
}
原文地址:https://www.cnblogs.com/applebox/p/11611611.html