diff --git a/PROMS/VEPROMS User Interface/Program.cs b/PROMS/VEPROMS User Interface/Program.cs index 2ff93064..248ea598 100644 --- a/PROMS/VEPROMS User Interface/Program.cs +++ b/PROMS/VEPROMS User Interface/Program.cs @@ -6,6 +6,7 @@ namespace VEPROMS { static class Program { + private static readonly log4net.ILog _log = log4net.LogManager.GetLogger(System.Reflection.MethodBase.GetCurrentMethod().DeclaringType); /// /// The main entry point for the application. /// @@ -14,7 +15,29 @@ namespace VEPROMS { Application.EnableVisualStyles(); Application.SetCompatibleTextRenderingDefault(false); - Application.Run(new frmVEPROMS()); + if (System.Diagnostics.Process.GetCurrentProcess().ProcessName.ToLower().EndsWith("vshost")) + { + Application.Run(new frmVEPROMS()); + } + else + { + Application.ThreadException += new System.Threading.ThreadExceptionEventHandler(Application_ThreadException); + Application.SetUnhandledExceptionMode(UnhandledExceptionMode.CatchException); + AppDomain.CurrentDomain.UnhandledException += new UnhandledExceptionEventHandler(CurrentDomain_UnhandledException); + Application.Run(new frmVEPROMS()); + } + } + + static void CurrentDomain_UnhandledException(object sender, UnhandledExceptionEventArgs e) + { + _log.Error("PROMS2010 Main UnhandledException", e.ExceptionObject as Exception); + Application.Exit(); + } + + static void Application_ThreadException(object sender, System.Threading.ThreadExceptionEventArgs e) + { + _log.Error("PROMS2010 Main ThreadException", e.Exception); + Application.Exit(); } } } \ No newline at end of file