幽幽Net

导航

WinForm应用只运行一次

一、WinForm应用只能运行一次

   static class Program
   {
        /// <summary>
        /// 应用程序的主入口点。
        /// </summary>
       [STAThread]
        static void Main()
        {
            bool createNew;
        //Using System.Threading;
            using (Mutex m = new Mutex(true, Application.ProductName, out createNew))
            {
                if (createNew)
                {
                    Application.EnableVisualStyles();
                    Application.SetCompatibleTextRenderingDefault(false);
                    Application.Run(new Form1());
                }
                else
                {
                    MessageBox.Show("该程序己启动");
                }
            }
        }
    }

 

posted on 2016-02-26 22:55  幽幽Net  阅读(554)  评论(0编辑  收藏  举报