123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657 |
- using AIDiagnosisDemo.Infrastucture;
- using System;
- using System.Diagnostics;
- using System.Windows;
- using System.Windows.Threading;
- namespace AIDiagnosisDemo
- {
- /// <summary>
- /// Interaction logic for App.xaml
- /// </summary>
- public partial class App : Application
- {
- protected override void OnStartup(StartupEventArgs e)
- {
- CheckedOpenRepeatedly();
- AppDomain.CurrentDomain.UnhandledException += OnDomainOnUnhandledException;
- Current.DispatcherUnhandledException += OnDispatcherUnhandledException;
- base.OnStartup(e);
- }
- private void OnDispatcherUnhandledException(object sender, DispatcherUnhandledExceptionEventArgs e)
- {
- Logger.Error($"OnDispatcherUnhandledException:{e.Exception}");
- e.Handled = true;
- Dispatcher.Invoke(() =>
- {
- MessageBox.Show($"OnDispatcherUnhandledException{e.Exception}");
- });
- }
- private void OnDomainOnUnhandledException(object sender, UnhandledExceptionEventArgs e)
- {
- Logger.Error($"OnDomainOnUnhandledException:{e.ExceptionObject}");
- Dispatcher.Invoke(() =>
- {
- MessageBox.Show($"OnDomainOnUnhandledException{e.ExceptionObject}");
- });
- }
- /// <summary>
- /// 判断是否重复打开
- /// </summary>
- private void CheckedOpenRepeatedly()
- {
- var thisProcess = Process.GetCurrentProcess();
- foreach (var item in Process.GetProcessesByName(thisProcess.ProcessName))
- {
- if (thisProcess.Id != item.Id)
- {
- MessageBox.Show("警告:程序正在运行中! 请不要重复打开程序!", "Warning", MessageBoxButton.OK, MessageBoxImage.Warning);
- thisProcess.Kill();
- }
- }
- }
- }
- }
|