using System.Windows; using System.Windows.Threading; using SpdUp.Core; namespace SpdUp; /// /// Interaction logic for App.xaml /// public partial class App : Application { protected override void OnStartup(StartupEventArgs e) { base.OnStartup(e); // Global exception handlers DispatcherUnhandledException += OnDispatcherUnhandledException; AppDomain.CurrentDomain.UnhandledException += OnDomainUnhandledException; TaskScheduler.UnobservedTaskException += OnUnobservedTaskException; // Enable required privileges early NativeMethods.EnablePrivilege(NativeMethods.SE_DEBUG_NAME); NativeMethods.EnablePrivilege(NativeMethods.SE_PROF_SINGLE_PROCESS_NAME); NativeMethods.EnablePrivilege(NativeMethods.SE_INC_BASE_PRIORITY_NAME); Logger.Info("SpdUp application starting."); } private void OnDispatcherUnhandledException(object sender, DispatcherUnhandledExceptionEventArgs e) { Logger.Error("Unhandled UI exception", e.Exception); MessageBox.Show($"An unexpected error occurred:\n{e.Exception.Message}", "SpdUp Error", MessageBoxButton.OK, MessageBoxImage.Error); e.Handled = true; } private static void OnDomainUnhandledException(object sender, UnhandledExceptionEventArgs e) { if (e.ExceptionObject is Exception ex) Logger.Error("Unhandled domain exception", ex); } private static void OnUnobservedTaskException(object? sender, UnobservedTaskExceptionEventArgs e) { Logger.Error("Unobserved task exception", e.Exception); e.SetObserved(); } }