C#应用程序单进程检测

以下程序经过VS2010测试通过:


     ///
/// 应用程序的主入口点。 /// [STAThread] static void Main() { CheckRun(); //Application.EnableVisualStyles(); //Application.SetCompatibleTextRenderingDefault(false); //Application.Run(new Form1()); } /// /// 单进程检测 /// private static void CheckRun() { bool isapprunning = false; System.Threading.Mutex mutex = new System.Threading.Mutex(true, System.Diagnostics.Process.GetCurrentProcess().ProcessName, out isapprunning); if (!isapprunning) { MessageBox.Show("本程序已经在运行了,请不要重复运行!"); Environment.Exit(1); } else { Application.EnableVisualStyles(); Application.SetCompatibleTextRenderingDefault(false); Application.Run(new Form1()); } }

 

转载于:https://www.cnblogs.com/gsk99/p/3456961.html

你可能感兴趣的:(C#应用程序单进程检测)