在“Program.cs”中添加以下代码:
[STAThread] static void Main() { Application.EnableVisualStyles(); Application.SetCompatibleTextRenderingDefault(false); bool blnIsRunning; Mutex mutexApp = new Mutex(false, Assembly.GetExecutingAssembly().FullName, out blnIsRunning); if (!blnIsRunning) { MessageBox.Show("Is Running!", "Warning", MessageBoxButtons.OK, MessageBoxIcon.Exclamation); return; } Application.Run(new Form1()); }
测试结果: