alielie
2025-03-03 4c3eb7f334abb8129b57e86f2935d75d0b3070b4
WPFProject/App.xaml.cs
@@ -1,9 +1,7 @@
using System;
using System.Collections.Generic;
using System.Configuration;
using System.Data;
using System.Linq;
using System.Threading.Tasks;
using HMI.UI.Util;
using log4net;
using Panuon.WPF.UI;
using System;
using System.Windows;
namespace WPFProject
@@ -13,14 +11,28 @@
    /// </summary>
    public partial class App : Application
    {
        public void test()
        private ILog log;
        public App()
        {
            log = LogManager.GetLogger("APP");
            AppDomain.CurrentDomain.UnhandledException += CurrentDomain_UnhandledException;
        }
        private void CurrentDomain_UnhandledException(object sender, UnhandledExceptionEventArgs e)
        {
            var ex = e.ExceptionObject as Exception;
            log.Error("UnhandledException.", ex);
            Dispatcher.Invoke(() =>
            {
                MsgBoxHelper.ErrorMessage(Current.MainWindow, $"发生未知异常!程序即将关闭\r\n{ex?.Message}",
                    "错误", MessageBoxButton.OK,
                    MessageBoxIcon.Error, DefaultButton.YesOK, 5);
            });
        }
        private void Application_Startup(object sender, StartupEventArgs e)
        {
            MainWindow window = new MainWindow();
            LoadingWindow window = new LoadingWindow();
            window.Show();
        }
    }