alielie
2026-09-10 9ec80cafc23f5ee3278cacce3c9f86f4087b435a
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
using System;
using System.Windows;
 
namespace TestSeq
{
 
    public class GlobalConfig
    {
        public double GlobalFontSize { get; set; } = 14;
    }
    public class GlobalConfigHolder
    {
        public static GlobalConfig Config { get; internal set; }
    }
 
    /// <summary>
    /// Interaction logic for App.xaml
    /// </summary>
    public partial class App : Application
    {
        public App()
        {
            AppDomain.CurrentDomain.FirstChanceException += CurrentDomain_FirstChanceException; ;
            AppDomain.CurrentDomain.UnhandledException += CurrentDomain_UnhandledException;
        }
 
        private void CurrentDomain_FirstChanceException(object sender, System.Runtime.ExceptionServices.FirstChanceExceptionEventArgs e)
        {
            //var ex = e.Exception;
            //MessageBox.Show(ex?.Message, "未知错误");
        }
 
        private void CurrentDomain_UnhandledException(object sender, UnhandledExceptionEventArgs e)
        {
            var ex = e.ExceptionObject as Exception;
            // Log.Error($"UnhandledException. {ex}");
            MessageBox.Show(ex?.Message, "未知错误");
        }
 
        protected override void OnStartup(StartupEventArgs e)
        {
            base.OnStartup(e);   // 放在最后,确保后续逻辑用到时已在内存
        }
 
        public void Application_Startup(object sender, StartupEventArgs e)
        {
            MainWindow window = new MainWindow();
            window.Show();
        }
    }
 
}