alielie
2025-03-11 2e54b439c64e0adbb7e010243c1f33aa5fc5f503
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
using HMI.Core.Util;
using HMI.UI.Util;
using log4net;
using Panuon.WPF.UI;
using System;
using System.IO;
using System.Windows;
using System.Windows.Markup;
using WPFProject.Utils;
 
namespace WPFProject
{
    /// <summary>
    /// App.xaml 的交互逻辑
    /// </summary>
    public partial class App : Application
    {
        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)
        {
            LangUtil.Load();
            ToastHelper.Register(new MainToastHandler());
            LoadingWindow window = new LoadingWindow();
            //Login window = new Login();
            window.Show();
        }
 
 
        private void LoadLang()
        {
            string path = "Lang/zh-CN/app.xaml";
            using (FileStream fs = new FileStream(path, FileMode.Open, FileAccess.Read))
            {
                var dict = (ResourceDictionary)XamlReader.Load(fs);
                Application.Current.Resources.MergedDictionaries.Add(dict);
            }
        }
    }
}