protected override void OnStartup(StartupEventArgs e) { instanceMutex = new Mutex(true, mutexName, out createdNew); if (!createdNew) { // App is already running! Exit the application and show the other window. InteropMethods.PostMessage((IntPtr)InteropMethods.HWND_BROADCAST, InteropMethods.WM_SHOWME, IntPtr.Zero, IntPtr.Zero); Current.Shutdown(); Environment.Exit(0); } GC.KeepAlive(instanceMutex); base.OnStartup(e); SplashWindow.Start(settings); }
private void Window_Loaded(object sender, RoutedEventArgs e) { // Window_Loaded 错误处理 try { SplashWindow.Start(); Thread.Sleep(1000); MainViewModel.Initial(); _runLedtimer.Interval = TimeSpan.FromSeconds(1); _runLedtimer.Start(); SplashWindow.Stop(); Activate(); } catch (Exception ex) { SplashWindow.ShowInfo("连接PLC失败"); Thread.Sleep(2000); SplashWindow.Stop(); Application.Current.Shutdown(0); } }