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

Contents of /trunk/TSControlPanel/Program.cs

Parent Directory Parent Directory | Revision Log Revision Log


Revision 67 - (show annotations) (download)
Thu Jul 12 19:34:37 2012 UTC (9 years, 2 months ago) by william
File size: 3601 byte(s)
Clone NDC stack within using statemnt

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

  ViewVC Help
Powered by ViewVC 1.1.22