#pragma warning restore IDE0052 protected override void OnStart() { /** * 应用程序单例模式 */ // ################################################################################# mutex = new Mutex(true, MUTEX_NAME, out bool createNew); if (!createNew) { // 此时还没有配置IoC,不能使用 DialogService MessageBox.Show("程序已在运行中。", "提示", MessageBoxButton.OK, MessageBoxImage.Information); InteropHelper.FindWindowAndActive(null, ShellViewModel.WindowName); // 激活已经存在的实例窗口 // 退出当前应用程序 // 尽量不要使用 // Application.Shutdown(); // 因为在这里使用会触发主窗口的Closing事件 Environment.Exit(0); } // ################################################################################# base.OnStart(); mutex.ReleaseMutex(); AppDomain.CurrentDomain.UnhandledException += CurrentDomain_UnhandledException; Initializer.Initialize(); }