Loading

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

        }

 

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

posted @ 2019-01-29 11:00  李正浩  阅读(127)  评论(0编辑  收藏  举报