Progam.cs 2.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263
  1. using System;
  2. using System.Collections.Generic;
  3. using System.Linq;
  4. using System.Text;
  5. using System.Windows.Forms;
  6. using System.Threading;
  7. using Aitex.Core.RT.Log;
  8. using Aitex.RT;
  9. namespace Aitex.Triton160.RT
  10. {
  11. static class Program
  12. {
  13. /// <summary>
  14. /// The main entry point for the application.
  15. /// </summary>
  16. [STAThread]
  17. static void Main()
  18. {
  19. AppDomain.CurrentDomain.UnhandledException += new UnhandledExceptionEventHandler(CurrentDomain_UnhandledException);
  20. AppDomain.CurrentDomain.ProcessExit += new EventHandler(CurrentDomain_ProcessExit);
  21. //Because this is a static event, you must detach your event handlers when your application is disposed, or memory leaks will result.
  22. Application.ThreadException += ThreadHandler;
  23. Application.SetUnhandledExceptionMode(UnhandledExceptionMode.CatchException);
  24. Application.EnableVisualStyles();
  25. Application.SetCompatibleTextRenderingDefault(false);
  26. Application.Run(new RtApplication());
  27. }
  28. static ThreadExceptionEventHandler ThreadHandler = new ThreadExceptionEventHandler(Application_ThreadException);
  29. static void CurrentDomain_ProcessExit(object sender, EventArgs e)
  30. {
  31. Application.ThreadException -= ThreadHandler;
  32. }
  33. static void Application_ThreadException(object sender, ThreadExceptionEventArgs e)
  34. {
  35. ShowMessageDialog(e.Exception);
  36. }
  37. static void CurrentDomain_UnhandledException(object sender, UnhandledExceptionEventArgs e)
  38. {
  39. ShowMessageDialog((Exception)e.ExceptionObject);
  40. }
  41. static void ShowMessageDialog(Exception ex)
  42. {
  43. try
  44. {
  45. LOG.Write(ex);
  46. string message = string.Format("Triton160 RT进程异常退出:{0}。\n", DateTime.Now);
  47. MessageBox.Show(message + ex.Message);
  48. }
  49. finally
  50. {
  51. Environment.Exit(0);
  52. }
  53. }
  54. }
  55. }