using System; using System.Threading; using System.Windows; namespace AnotherReplayReader { /// /// App.xaml 的交互逻辑 /// public partial class App : Application { private int _isInException = 0; public App() { AppDomain.CurrentDomain.UnhandledException += (sender, eventArgs) => { if (Interlocked.Increment(ref _isInException) > 1) { return; } Dispatcher.Invoke(() => { const string message = "哎呀呀,出现了一些无法处理的问题,只能退出了。要不要尝试保存一下日志文件呢?"; var choice = MessageBox.Show($"{message}\r\n{eventArgs.ExceptionObject}", "自动录像机", MessageBoxButton.YesNo); if (choice == MessageBoxResult.Yes) { Debug.Instance.RequestSave(); } }); }; } } }