[WPF]限制程序单例运行

代码

        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);

        }

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

原文地址:https://www.cnblogs.com/lizhenghao126/p/11053587.html