Program.cs 3.2 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980
  1. using ProjectManagementSystem.Common.Extenions;
  2. using System;
  3. using System.Collections.Generic;
  4. using System.Linq;
  5. using System.Threading.Tasks;
  6. using System.Windows.Forms;
  7. namespace ProjectManagementSystem
  8. {
  9. static class Program
  10. {
  11. /// <summary>
  12. /// 应用程序的主入口点。
  13. /// </summary>
  14. [STAThread]
  15. static void Main()
  16. {
  17. Application.EnableVisualStyles();
  18. Application.SetCompatibleTextRenderingDefault(false);
  19. //Application.Run(new MainForm());
  20. Program.InitApplication();
  21. }
  22. public static void InitApplication()
  23. {
  24. System.Windows.Forms.Application.ThreadException += Application_ThreadException;
  25. System.AppDomain.CurrentDomain.UnhandledException += CurrentDomain_UnhandledException;
  26. try
  27. {
  28. bool flag;
  29. using (new System.Threading.Mutex(true, "Global\\" + System.Windows.Forms.Application.ProductName, out flag))
  30. {
  31. if (flag)
  32. {
  33. string cultureInfo = Common.Function.AppSetting.TryGetValue<string>("CultureInfo");
  34. if(!string.IsNullOrEmpty(cultureInfo))
  35. {
  36. System.Threading.Thread.CurrentThread.CurrentUICulture = new System.Globalization.CultureInfo(cultureInfo);
  37. }
  38. Application.Run(new MainForm());
  39. }
  40. else
  41. {
  42. MessageBox.Show("应用程序只能启动一个实例!!!");
  43. Application.Exit();
  44. }
  45. }
  46. }
  47. catch (System.Exception exception)
  48. {
  49. Common.Logger.CLog.Instance.SystemLog.WriteExceptionCaller(exception);
  50. MessageBox.Show("应用程序运行异常!!!" + exception.Message, "提示", MessageBoxButtons.OK, MessageBoxIcon.Error);
  51. Application.Exit();
  52. }
  53. }
  54. private static void CurrentDomain_UnhandledException(object sender, UnhandledExceptionEventArgs e)
  55. {
  56. Exception exception = e.ExceptionObject as Exception;
  57. Common.Logger.CLog.Instance.SystemLog.WriteExceptionCaller(exception);
  58. if (exception.InnerException != null)
  59. {
  60. Common.Logger.CLog.Instance.SystemLog.WriteExceptionCaller(exception.InnerException);
  61. }
  62. MessageBox.Show("应用程序有未处理的异常!!!" + exception.Message, "提示", MessageBoxButtons.OK, MessageBoxIcon.Error);
  63. }
  64. private static void Application_ThreadException(object sender, System.Threading.ThreadExceptionEventArgs e)
  65. {
  66. Common.Logger.CLog.Instance.SystemLog.WriteExceptionCaller(e.Exception);
  67. if (e.Exception.InnerException != null)
  68. {
  69. Common.Logger.CLog.Instance.SystemLog.WriteExceptionCaller(e.Exception.InnerException);
  70. }
  71. MessageBox.Show("应用程序线程异常!!!" + e.Exception.Message, "提示", MessageBoxButtons.OK, MessageBoxIcon.Error);
  72. }
  73. }
  74. }