wpf防止打开程序多个窗口

        private System.Threading.Mutex mutex;

        public App()
        {
            this.Startup += new StartupEventHandler(App_Startup);
        }

        private void App_Startup(object sender, StartupEventArgs e)
        {
            bool ret;
            mutex = new System.Threading.Mutex(true, "name", out ret);

            if (!ret)
            {
                MessageBox.Show("该系统已打开,请勿重复开启!", "", MessageBoxButton.OK, MessageBoxImage.Warning);
                Environment.Exit(0);
            }
        }

 

posted @ 2024-09-26 17:30  echo-efun  阅读(141)  评论(0)    收藏  举报