版权声明:转载请标注原文地址。【邮箱[email protected]】 https://blog.csdn.net/weixin_42032900/article/details/81191006
winform 应用程序只启动一次
思路:捕获系统进程,是否和当前进程有一致的
引用程序集:using System.Diagnostics;
static class Program
{
/// <summary>
/// 应用程序的主入口点。
/// </summary>
[STAThread]
static void Main()
{
int count = 0;
Process[] myProcess = Process.GetProcesses();
foreach (Process _Process in myProcess)
{
if (_Process.ProcessName == Process.GetCurrentProcess().ProcessName)
{
count++;
}
}
if (count > 1)
{
MessageBox.Show("请勿重复打开软件");
}
else
{
Application.EnableVisualStyles();
//Application.SetCompatibleTextRenderingDefault(true);
Application.Run(new FormMain());
}
}
}