[WPF]限制程序单例运行

版权声明:本文为本人原创文章,未经博主允许不得转载。 https://blog.csdn.net/m0_37316917/article/details/86686945

代码

        System.Threading.Mutex mutex;
        protected override void OnStartup(StartupEventArgs e)
        {
            bool ret;
            mutex = new System.Threading.Mutex(true, "StikyNotesAPP", out ret);

            if (!ret)
            {
                MessageBox.Show("程序已经运行了");
                Environment.Exit(0);
            }

            base.OnStartup(e);

        }

如果已经有一个程序在运行的话,就会弹框提示

猜你喜欢

转载自blog.csdn.net/m0_37316917/article/details/86686945