Files
FootwearTest-20260602/Footwear Test methodsfor wholeshoe Slipresistanceperformance/App.axaml.cs
2026-06-02 18:45:14 +08:00

68 lines
2.0 KiB
C#
Raw Blame History

This file contains ambiguous Unicode characters
This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.
using Avalonia;
using Avalonia.Controls.ApplicationLifetimes;
using Avalonia.Data.Core;
using Avalonia.Data.Core.Plugins;
using Avalonia.Markup.Xaml;
using Footwear_Test_methodsfor_wholeshoe_Slipresistanceperformance.ViewModels;
using Footwear_Test_methodsfor_wholeshoe_Slipresistanceperformance.Views;
using Serilog;
using System;
using System.Linq;
using System.Threading.Tasks;
namespace Footwear_Test_methodsfor_wholeshoe_Slipresistanceperformance
{
public partial class App : Application
{
private static bool exceptionHandlersRegistered;
public override void Initialize()
{
AvaloniaXamlLoader.Load(this);
}
public override void OnFrameworkInitializationCompleted()
{
RegisterExceptionHandlers();
if (ApplicationLifetime is IClassicDesktopStyleApplicationLifetime desktop)
{
desktop.MainWindow = new MainWindow
{
DataContext = new MainWindowViewModel(),
};
}
base.OnFrameworkInitializationCompleted();
}
private static void RegisterExceptionHandlers()
{
if (exceptionHandlersRegistered)
{
return;
}
AppDomain.CurrentDomain.UnhandledException += (_, args) =>
{
if (args.ExceptionObject is Exception exception)
{
Log.Fatal(exception, "捕获到 AppDomain 未处理异常IsTerminating={IsTerminating}", args.IsTerminating);
}
else
{
Log.Fatal("捕获到 AppDomain 未处理异常:{ExceptionObject}", args.ExceptionObject);
}
};
TaskScheduler.UnobservedTaskException += (_, args) =>
{
Log.Error(args.Exception, "捕获到未观察的后台任务异常");
args.SetObserved();
};
exceptionHandlersRegistered = true;
}
}
}