Program.cs 3.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384
  1. using ComponentFactory.Krypton.Toolkit;
  2. using System;
  3. using System.Collections.Generic;
  4. using System.Diagnostics;
  5. using System.Linq;
  6. using System.Threading;
  7. using System.Windows.Forms;
  8. namespace Falit.Run
  9. {
  10. static class Program
  11. {
  12. /// <summary>
  13. /// 应用程序的主入口点。
  14. /// </summary>
  15. public static ApplicationContext context;
  16. /// <summary>
  17. /// 应用程序的主入口点。
  18. /// </summary>
  19. [STAThread]
  20. static void Main()
  21. {
  22. //try
  23. //{
  24. Application.SetUnhandledExceptionMode(UnhandledExceptionMode.CatchException);
  25. //Application.ThreadException += Application_ThreadException;
  26. //AppDomain.CurrentDomain.UnhandledException += CurrentDomain_UnhandledException;
  27. var processName = Process.GetCurrentProcess().ProcessName;
  28. if ((Process.GetProcessesByName(processName)).GetUpperBound(0) > 0)
  29. {
  30. KryptonMessageBox.Show(@"系统已经在运行中,如果要重新启动,请从进程中关闭...", @"系统警告", MessageBoxButtons.OK, MessageBoxIcon.Asterisk);
  31. }
  32. else
  33. {
  34. Application.EnableVisualStyles();
  35. Application.SetCompatibleTextRenderingDefault(false);
  36. var upgrade = new FrmUpgrade();
  37. upgrade.Show();
  38. //context = new ApplicationContext();
  39. //context.Tag = upgrade;
  40. //Application.Idle += Application_Idle; //注册程序运行空闲去执行主程序窗体相应初始化代码
  41. Application.Run(upgrade);
  42. }
  43. //}
  44. //catch (Exception ex)
  45. //{
  46. // KryptonMessageBox.Show("系统出现未知异常,请重启系统:" + ex.Message, "系统错误", MessageBoxButtons.OK, MessageBoxIcon.Error);
  47. //}
  48. }
  49. //private static void Application_ThreadException(object sender, ThreadExceptionEventArgs e)
  50. //{
  51. // var ex = e.Exception.InnerException;
  52. // if (ex != null)
  53. // {
  54. // KryptonMessageBox.Show("系统出现未知异常," + ex.Message, "系统错误", MessageBoxButtons.OK, MessageBoxIcon.Error);
  55. // }
  56. //}
  57. //private static void CurrentDomain_UnhandledException(object sender, UnhandledExceptionEventArgs e)
  58. //{
  59. // var ex = e.ExceptionObject as Exception;
  60. // if (ex != null)
  61. // {
  62. // KryptonMessageBox.Show("系统出现未知异常," + ex.InnerException.Message, "系统错误", MessageBoxButtons.OK, MessageBoxIcon.Error);
  63. // }
  64. //}
  65. //private static void Application_Idle(object sender, EventArgs e)
  66. //{
  67. // Application.Idle -= Application_Idle;
  68. // if (context.MainForm == null)
  69. // {
  70. // var login = new FrmUpgrade();
  71. // context.MainForm = login;
  72. // var sp = (FrmUpgrade)context.Tag;
  73. // sp.Close();
  74. // login.Show();
  75. // }
  76. //}
  77. }
  78. }