App.xaml.cs 1.3 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647
  1. using AwInitilizer.DLL;
  2. using System;
  3. using System.Collections.Generic;
  4. using System.Configuration;
  5. using System.Data;
  6. using System.IO;
  7. using System.Linq;
  8. using System.Text;
  9. using System.Threading.Tasks;
  10. using System.Windows;
  11. namespace AwInitilizer
  12. {
  13. /// <summary>
  14. /// Interaction logic for App.xaml
  15. /// </summary>
  16. public partial class App : Application
  17. {
  18. public App():base()
  19. {
  20. DispatcherUnhandledException += App_DispatcherUnhandledException;
  21. }
  22. protected override void OnActivated(EventArgs e)
  23. {
  24. base.OnActivated(e);
  25. var startResult = SajetConnect.SajetTransStart();
  26. }
  27. private void App_DispatcherUnhandledException(object sender, System.Windows.Threading.DispatcherUnhandledExceptionEventArgs e)
  28. {
  29. var fileName = DateTime.Now.ToString("yyyyMMddHHmmss") + ".txt";
  30. File.WriteAllText(fileName,e.Exception.Message);
  31. File.WriteAllText(fileName, e.Exception.StackTrace);
  32. MessageBox.Show($"App crashed,Please report error and send back {fileName}");
  33. Application.Current.Shutdown();
  34. }
  35. protected override void OnExit(ExitEventArgs e)
  36. {
  37. base.OnExit(e);
  38. var stopResult = SajetConnect.SajetTransClose();
  39. }
  40. }
  41. }