单实例运行

  [STAThread]
        static void Main()
        {
            Application.EnableVisualStyles();
            Application.SetCompatibleTextRenderingDefault(false);
            System.Threading.Mutex mutex = new System.Threading.Mutex(false, "SINGLE_INSTANCE_MUTEX");
            if (!mutex.WaitOne(0, false))
            {
                mutex.Close();
                mutex = null;
            }
            if (mutex != null)
            {
                Application.Run(new Form1());
            }
            else
            {
                MessageBox.Show("程序已经启动 ");
            }
        }
posted @ 2013-01-05 18:23  程序有Bug  阅读(111)  评论(0编辑  收藏  举报