winfrom防止程序多開

在program的mian方法中添加如下代碼:

        static void Main()
        {
            bool started = true;
            using (new Mutex(true, Assembly.GetExecutingAssembly().FullName, out started))
            {
                if (!started)
                {
                    MessageBox.Show("程序已啓動!");
                    System.Environment.Exit(0);
                }
                else
                {
                    Application.EnableVisualStyles();
                    Application.SetCompatibleTextRenderingDefault(false);
                    Application.Run(new FrmLogin());
                }
            }
        }

 

發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章