保证该程序只有一个在运行

 //保证该程序只有一个在运行
            bool createdNew;
            System.Threading.Mutex mutex_Application = new System.Threading.Mutex(true, "Robot", out createdNew);
            if (!createdNew)
            {
                MessageBox.Show("本程序只允许同时运行一个!");
                return;
            }

            Login Lrm = new Login();
            if (DialogResult.OK == Lrm.ShowDialog())
            {
                Mywork MyMainForm = new Mywork();
                Application.Run(MyMainForm);
            }
            else
            {
                Application.Exit();
            }

原文地址:https://www.cnblogs.com/RobotTech/p/974344.html