App.xaml.cs 1.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051
  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. //Cultures.CulturesHelper.Instance.ChangeCulture(System.Globalization.CultureInfo.GetCultureInfo("zh-CHS"));
  27. Cultures.CulturesHelper.Instance.ChangeCulture(System.Globalization.CultureInfo.GetCultureInfo("en-US"));
  28. }
  29. private void App_DispatcherUnhandledException(object sender, System.Windows.Threading.DispatcherUnhandledExceptionEventArgs e)
  30. {
  31. var fileName = DateTime.Now.ToString("yyyyMMddHHmmss") + ".txt";
  32. var msg = e.Exception.Message + "\n"+ e.Exception.StackTrace;
  33. File.WriteAllText(fileName,msg);
  34. MessageBox.Show($"App crashed,Please report error and send back {fileName}");
  35. Application.Current.Shutdown();
  36. }
  37. protected override void OnExit(ExitEventArgs e)
  38. {
  39. base.OnExit(e);
  40. var stopResult = SajetConnect.SajetTransClose();
  41. Environment.Exit(0);
  42. }
  43. }
  44. }