C#禁止程序多开

                    bool createdNew; //返回是否赋予了使用线程的互斥体初始所属权
                    System.Threading.Mutex instance = new System.Threading.Mutex(true, "MutexName", out createdNew); //同步基元变量
                    if (createdNew) //赋予了线程初始所属权,也就是首次使用互斥体

                    {

                        //没有多开,程序初始化

                        Convert.ToDateTime(key);
                        Application.EnableVisualStyles();
                        Application.SetCompatibleTextRenderingDefault(false);
                        Application.Run(new Form1(key));
                    }
                    else
                    {
                        MessageBox.Show("已经启动了一个程序,请先退出!", "系统提示", MessageBoxButtons.OK, MessageBoxIcon.Error);
                        Application.Exit();
                    }

猜你喜欢

转载自blog.csdn.net/a1003434346/article/details/80778101
今日推荐