-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathApp.xaml.cs
More file actions
57 lines (50 loc) · 1.71 KB
/
App.xaml.cs
File metadata and controls
57 lines (50 loc) · 1.71 KB
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 System;
using System.Windows;
using System.Windows.Threading;
namespace NetIsolatePlus;
public partial class App : Application
{
public App()
{
this.DispatcherUnhandledException += (s, e) =>
{
try
{
if (Current?.Dispatcher?.HasShutdownStarted == true) return;
MessageBox.Show("Unhandled error:\n\n" + e.Exception, "NetIsolate+",
MessageBoxButton.OK, MessageBoxImage.Error);
e.Handled = true; // prevent silent exit
}
catch
{
// last resort: let it crash if we can't show UI
}
};
AppDomain.CurrentDomain.UnhandledException += (s, e) =>
{
try
{
var ex = e.ExceptionObject as Exception;
var msg = "Fatal error:\n\n" + ex;
// This can fire on a non-UI thread; only attempt UI marshal (avoid blocking/hanging here).
if (Current?.Dispatcher != null && !Current.Dispatcher.HasShutdownStarted)
{
Current.Dispatcher.BeginInvoke(new Action(() =>
{
try
{
if (Current?.Dispatcher?.HasShutdownStarted == true) return;
MessageBox.Show(msg, "NetIsolate+",
MessageBoxButton.OK, MessageBoxImage.Error);
}
catch { }
}), DispatcherPriority.Send);
}
}
catch
{
// swallow; nothing reliable to do here
}
};
}
}