/[AnywhereTS-MSSQL]/trunk/TSControlPanel/Program.cs
ViewVC logotype

Annotation of /trunk/TSControlPanel/Program.cs

Parent Directory Parent Directory | Revision Log Revision Log


Revision 65 - (hide annotations) (download)
Thu Jul 12 19:07:58 2012 UTC (9 years ago) by william
File size: 2564 byte(s)
also use bApplication.ThreadException in addition to AppDomain.UnhandledException

1 william 4 using System;
2     using System.Collections.Generic;
3     using System.Windows.Forms;
4 william 52 using System.Data.SqlClient;
5 william 4
6     namespace AnywhereTS
7     {
8     static class Program
9     {
10     /// <summary>
11     /// The main entry point for the application.
12     /// </summary>
13     [STAThread]
14     static void Main()
15 william 61 {
16     AppDomain currentDomain = AppDomain.CurrentDomain;
17     currentDomain.UnhandledException += new UnhandledExceptionEventHandler(CurrentDomain_UnhandledException);
18     Application.SetUnhandledExceptionMode(UnhandledExceptionMode.CatchException, true);
19    
20 william 65 Application.ThreadException += new System.Threading.ThreadExceptionEventHandler(Application_ThreadException);
21    
22 william 4 Application.EnableVisualStyles();
23     Application.SetCompatibleTextRenderingDefault(false);
24    
25     frmClientProperties objCustomDialogBox = new frmClientProperties();
26     objCustomDialogBox.dialogMode = frmClientProperties.ATSClientMode.CONTROL_PANEL; // Select the mode to run the form in.
27     Application.Run(objCustomDialogBox);
28     }
29 william 65
30     static void Application_ThreadException(object sender, System.Threading.ThreadExceptionEventArgs e)
31     {
32     CurrentDomain_UnhandledException(sender, new UnhandledExceptionEventArgs(e.Exception, false));
33     }
34 william 61 static void CurrentDomain_UnhandledException(object sender, UnhandledExceptionEventArgs args)
35     {
36     Exception e = (Exception)args.ExceptionObject;
37     if (e == null)
38     {
39     Logging.ATSAdminLog.Error("Encountered unhandled Exception, but the exception was null");
40     return;
41     }
42     if (e.GetType() == typeof(SqlException))
43     {
44     SqlException sql_ex = (e as SqlException);
45     using (log4net.NDC.Push(string.Format("SqlException: ID={0} MESSAGE={1}{2}Diagnostics:{2}{3}", sql_ex.Number.ToString(), sql_ex.Message, System.Environment.NewLine, sql_ex.ToString())))
46     {
47     Logging.ATSAdminLog.Error("Encountered unhandled SqlException");
48     }
49     }
50     else
51     {
52     using (log4net.NDC.Push(string.Format("Exception: MESSAGE={0}{1}Diagnostics:{1}{2}", e.Message, System.Environment.NewLine, e.ToString())))
53     {
54     Logging.ATSAdminLog.Error("Encountered unhandled Exception");
55     }
56     }
57     }
58 william 4 }
59     }

  ViewVC Help
Powered by ViewVC 1.1.22