本文实例讲述了C#使用Mutex简单实现程序单实例运行的方法。分享给大家供大家参考。具体如下:
?| 1234567891011121314 | [STAThread] static void Main() {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());}} |
希望本文所述对大家的C#程序设计有所帮助。








发表评论
◎欢迎参与讨论,请在这里发表您的看法、交流您的观点。