首页 > 代码库 > Program.cs 累积_C#

Program.cs 累积_C#

 1 using System;
 2 using System.Diagnostics;
 3 using System.Threading;
 4 using System.Windows.Forms;
 5 using UtilityClass;
 6 
 7 namespace Program
 8 {
 9     static class Program
10     {
11         /// <summary>
12         /// 应用程序的主入口点。
13         /// </summary>
14         [STAThread]
15         static void Main()
16         {
17             // 增加捕获
18             ApplicationEventHandlerClass AppEvents = new ApplicationEventHandlerClass();
19             Application.ThreadException += new ThreadExceptionEventHandler(AppEvents.OnThreadException);
20 
21             // 开始监听
22             Trace.Listeners.Clear();
23             Trace.Listeners.Add(new TraceLog(Application.StartupPath + "\\Error.Log"));
24 
25             Application.EnableVisualStyles();
26             Application.SetCompatibleTextRenderingDefault(false);
27             if (new FormLogin().ShowDialog() == DialogResult.OK)
28                 Application.Run(FormMain.Instance);
29         }
30 
31         public class ApplicationEventHandlerClass
32         {
33             public void OnThreadException(object sender, ThreadExceptionEventArgs e)
34             {
35                 Trace.Write(e.Exception, "未捕获的异常");
36                 ShowMsg.ShowErr(sender as IWin32Window, "程序出现错误:\r\n" + e.Exception.Message + "\r\n\r\n请联系管理员以解决此问题!");
37             }
38         }
39     }
40 }