1 static class Program
2 {
3 //Mutex:一个同步基元,也可用于进程间同步。
4 private static System.Threading.Mutex mutex;
5
6 /// <summary>
7 /// 应用程序的主入口点。
8 /// </summary>
9 [STAThread]
10 static void Main()
11 {
12 Application.EnableVisualStyles();
13 Application.SetCompatibleTextRenderingDefault(false);
14 //实例化Mutex。
15 mutex = new System.Threading.Mutex(true, "OnlyRun");
16 if (mutex.WaitOne(0, false))
17 {
18 Application.Run(new MainForm());
19 }
20 else
21 {
22 MessageBox.Show("程序已经运行!", "提示", MessageBoxButtons.OK, MessageBoxIcon.Information);
23 Application.Exit();
24 }
25 }
26 }