App.xaml.cs 1.5 KB

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