Program.cs 2.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172
  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. MessageBox.Show("应用程序有未处理的异常!!!" + exception.Message, "提示", MessageBoxButtons.OK, MessageBoxIcon.Error);
  59. }
  60. private static void Application_ThreadException(object sender, System.Threading.ThreadExceptionEventArgs e)
  61. {
  62. Common.Logger.CLog.Instance.SystemLog.WriteExceptionCaller(e.Exception);
  63. MessageBox.Show("应用程序线程异常!!!" + e.Exception.Message, "提示", MessageBoxButtons.OK, MessageBoxIcon.Error);
  64. }
  65. }
  66. }