App.xaml.cs 964 B

12345678910111213141516171819202122232425262728293031
  1. using System;
  2. using System.Collections.Generic;
  3. using System.Configuration;
  4. using System.Data;
  5. using System.IO;
  6. using System.Linq;
  7. using System.Threading.Tasks;
  8. using System.Windows;
  9. namespace AwInitilizer
  10. {
  11. /// <summary>
  12. /// Interaction logic for App.xaml
  13. /// </summary>
  14. public partial class App : Application
  15. {
  16. public App():base()
  17. {
  18. DispatcherUnhandledException += App_DispatcherUnhandledException;
  19. }
  20. private void App_DispatcherUnhandledException(object sender, System.Windows.Threading.DispatcherUnhandledExceptionEventArgs e)
  21. {
  22. var fileName = DateTime.Now.ToString("yyyyMMddHHmmss") + ".txt";
  23. File.WriteAllText(fileName,e.Exception.Message);
  24. File.WriteAllText(fileName, e.Exception.StackTrace);
  25. MessageBox.Show($"App crashed,Please report error and send back {fileName}");
  26. Application.Current.Shutdown();
  27. }
  28. }
  29. }