Program.cs 1.8 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344
  1. using DevExpress.LookAndFeel;
  2. using DevExpress.Skins;
  3. using DevExpress.UserSkins;
  4. using System;
  5. using System.Collections.Generic;
  6. using System.Linq;
  7. using System.Reflection;
  8. using System.Windows.Forms;
  9. namespace DataSimulation.Forms
  10. {
  11. internal static class Program
  12. {
  13. static Program()
  14. {
  15. AppDomain.CurrentDomain.SetData("PRIVATE_BINPATH", "AddIns;");
  16. string paths = Environment.GetEnvironmentVariable("PATH");
  17. var m = typeof(AppDomainSetup).GetMethod("UpdateContextProperty", BindingFlags.NonPublic | BindingFlags.Static);
  18. var funsion = typeof(AppDomain).GetMethod("GetFusionContext", BindingFlags.NonPublic | BindingFlags.Instance);
  19. m.Invoke(null, new object[] { funsion.Invoke(AppDomain.CurrentDomain, null), "PRIVATE_BINPATH", "AddIns;" });
  20. AppDomain.CurrentDomain.UnhandledException += (sender, e) =>
  21. {
  22. var args = e.ExceptionObject as Exception;
  23. Serilog.Log.Error(args, "出现未处理的异常,程序即将退出!");
  24. DxHelper.MsgBoxHelper.ShowError("出现未处理的异常,程序即将退出!");
  25. };
  26. Application.ThreadException += (sender, e) =>
  27. {
  28. DxHelper.MsgBoxHelper.ShowError($"出现未处理的线程异常!{e.Exception.Message}");
  29. Serilog.Log.Error(e.Exception, "出现未处理的线程异常");
  30. };
  31. }
  32. /// <summary>
  33. /// The main entry point for the application.
  34. /// </summary>
  35. [STAThread]
  36. static void Main()
  37. {
  38. Application.EnableVisualStyles();
  39. Application.SetCompatibleTextRenderingDefault(false);
  40. Application.Run(new MainForm());
  41. }
  42. }
  43. }