美文网首页
C#Winform如何禁止应用程序重复打开

C#Winform如何禁止应用程序重复打开

作者: your_god | 来源:发表于2018-04-20 16:09 被阅读0次

    话不多说,直接上代码:

    static void Main()

            {

                System.Threading.Mutex mutex = new System.Threading.Mutex(false, "命名空间");

                bool running = !mutex.WaitOne(0, false);

                if (!running)

                    Application.Run(new FrmLogin());//FrmLogin为主窗体名

                else

                    MessageBox.Show("程序已运行!");

            }

    用到了Mutex类;Mutex类详细解析:https://msdn.microsoft.com/zh-cn/library/system.threading.mutex.aspx

    相关文章

      网友评论

          本文标题:C#Winform如何禁止应用程序重复打开

          本文链接:https://www.haomeiwen.com/subject/izqzkftx.html