App.xaml.cs 1.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445
  1. using System;
  2. using System.Collections.Generic;
  3. using System.Configuration;
  4. using System.Data;
  5. using System.Linq;
  6. using System.Threading.Tasks;
  7. using System.Windows;
  8. using System.Windows.Threading;
  9. using Vinno.IUS.Common.Log;
  10. namespace vCloud.GeneratePackages.Tool
  11. {
  12. /// <summary>
  13. /// Interaction logic for App.xaml
  14. /// </summary>
  15. public partial class App : Application
  16. {
  17. protected override void OnStartup(StartupEventArgs e)
  18. {
  19. AppManager.MainDispatcher = Current.Dispatcher;
  20. AppDomain.CurrentDomain.UnhandledException += OnDomainUnhandledException;
  21. Current.DispatcherUnhandledException += OnCurrentDispatcherUnhandledException;
  22. base.OnStartup(e);
  23. }
  24. private void OnDomainUnhandledException(object sender, UnhandledExceptionEventArgs e)
  25. {
  26. Logger.WriteLineError($"OnDomainUnhandledException: {e.ExceptionObject}");
  27. Dispatcher.Invoke(() =>
  28. {
  29. MessageBox.Show($"OnDomainUnhandledException{e.ExceptionObject}");
  30. });
  31. }
  32. private void OnCurrentDispatcherUnhandledException(object sender, DispatcherUnhandledExceptionEventArgs e)
  33. {
  34. Logger.WriteLineError($"OnCurrentDispatcherUnhandledException: {e.Exception}");
  35. Dispatcher.Invoke(() =>
  36. {
  37. MessageBox.Show($"OnCurrentDispatcherUnhandledException: {e.Exception}");
  38. });
  39. }
  40. }
  41. }