App.xaml.cs 2.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475
  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.Shapes;
  9. namespace Muchinfo.MTPClient.Update
  10. {
  11. /// <summary>
  12. /// App.xaml 的交互逻辑
  13. /// </summary>
  14. public partial class App : Application
  15. {
  16. App()
  17. {
  18. this.DispatcherUnhandledException += App_DispatcherUnhandledException;
  19. }
  20. void App_DispatcherUnhandledException(object sender, System.Windows.Threading.DispatcherUnhandledExceptionEventArgs e)
  21. {
  22. try
  23. {
  24. if (! (e.Exception.InnerException is System.Net.Sockets.SocketException))
  25. {
  26. var tipWindow = new TipsWindow(e.Exception.Message);
  27. tipWindow.ShowDialog();
  28. // MessageBox.Show(e.Exception.Message, "交易端更新提示");
  29. e.Handled = true;
  30. }
  31. }
  32. catch (Exception ex)
  33. {
  34. }
  35. Environment.Exit(0);
  36. }
  37. protected override void OnStartup(StartupEventArgs e)
  38. {
  39. base.OnStartup(e);
  40. if (e.Args.Length > 0)
  41. {
  42. string[] str = e.Args[0].Split(',');
  43. this.ShutdownMode = ShutdownMode.OnExplicitShutdown;
  44. if (str.Length>=1)
  45. {
  46. string applictionUpdateUrl = str[0];
  47. string memberCode = str.Length==2? str[1]:string.Empty;
  48. var updateInto = UpdateManage.RunUpdate(applictionUpdateUrl, memberCode);
  49. if (updateInto != null)
  50. {
  51. UpdateForm mWindow = new UpdateForm(applictionUpdateUrl, updateInto);
  52. this.MainWindow = mWindow;
  53. mWindow.Show();
  54. }
  55. else
  56. {
  57. Environment.Exit(0);
  58. }
  59. }
  60. }
  61. else
  62. {
  63. Environment.Exit(0);
  64. }
  65. }
  66. }
  67. }