1, 在winform项目中 Program.cs 文件里添加
using System; using System.Collections.Generic; using System.Diagnostics; using System.Linq; using System.Threading.Tasks; using System.Windows.Forms; namespace SMProjectSysetm { internal static class Program { /// <summary> /// 应用程序的主入口点。 /// </summary> [STAThread] static void Main() { Application.EnableVisualStyles(); Application.SetCompatibleTextRenderingDefault(false); //禁止启动多个项目进程 Process[] process = Process.GetProcesses(); //获取所有进程 int count = 0; foreach (Process item in process) { if (item.ProcessName == Process.GetCurrentProcess().ProcessName) { count += 1; } } if (count > 1) //当前进程数量多于1个的时候,禁止再次打开一个进程 { Application.Exit(); return; } FrmLogin frmLogin = new FrmLogin(); DialogResult result = frmLogin.ShowDialog(); if (result == DialogResult.OK) { Application.Run(new FrmMain()); } } } }
标签:禁止,Process,System,Application,exe,进程,using,winform From: https://www.cnblogs.com/tlfe/p/18254557