private static void Main(string[] args) { initialiseFiles(); Updater.MakeSquirrelAware(); Application.EnableVisualStyles(); Application.SetCompatibleTextRenderingDefault(false); delayStartup(); Splash.ShowMe(); log.Debug("Loading settings from file."); Settings.Load(); Updater = new Updater(); isNewVersion(Updater.IsSquirrelInstall()); Updater.CheckForUpdate(); TimezoneDB.Instance.CheckForUpdate(); try { try { Application.Run(new MainForm(startingTab)); } catch (ApplicationException ex) { log.Fatal(ex.Message); MessageBox.Show(ex.Message, "Application terminated!", MessageBoxButtons.OK, MessageBoxIcon.Exclamation); throw new ApplicationException(ex.Message.StartsWith("COM error") ? "Suggest startup delay" : ""); } catch (System.Runtime.InteropServices.COMException ex) { OGCSexception.Analyse(ex); throw new ApplicationException("Suggest startup delay"); } catch (System.Exception ex) { OGCSexception.Analyse(ex); log.Fatal("Application unexpectedly terminated!"); MessageBox.Show(ex.Message, "Application unexpectedly terminated!", MessageBoxButtons.OK, MessageBoxIcon.Error); throw new ApplicationException(); } } catch (ApplicationException aex) { if (aex.Message == "Suggest startup delay") { if (isCLIstartup() && Settings.Instance.StartOnStartup) { log.Debug("Suggesting to set a startup delay."); MessageBox.Show("If this error only happens when logging in to Windows, try " + ((Settings.Instance.StartupDelay == 0) ? "setting a" : "increasing the") + " delay for OGCS on startup.", "Set a delay on startup", MessageBoxButtons.OK, MessageBoxIcon.Information); } } log.Warn("Tidying down any remaining Outlook references, as OGCS crashed out."); try { if (!OutlookCalendar.IsInstanceNull) { OutlookCalendar.InstanceConnect = false; OutlookCalendar.Instance.IOutlook.Disconnect(); } } catch { } } Splash.CloseMe(); GC.Collect(); GC.WaitForPendingFinalizers(); while (Updater.IsBusy) { Application.DoEvents(); System.Threading.Thread.Sleep(100); } log.Info("Application closed."); }
private static void Main(string[] args) { initialiseFiles(); Updater.MakeSquirrelAware(); Application.EnableVisualStyles(); Application.SetCompatibleTextRenderingDefault(false); delayStartup(); Splash.ShowMe(); log.Debug("Loading settings from file."); Settings.Load(); Updater = new Updater(); isNewVersion(Updater.IsSquirrelInstall()); Updater.CheckForUpdate(); TimezoneDB.Instance.CheckForUpdate(); try { try { Application.Run(new MainForm(startingTab)); } catch (ApplicationException ex) { log.Fatal(ex.Message); MessageBox.Show(ex.Message, "Application terminated!", MessageBoxButtons.OK, MessageBoxIcon.Exclamation); throw new ApplicationException(); } catch (System.Runtime.InteropServices.COMException ex) { if (OGCSexception.GetErrorCode(ex, 0x000FFFFF) == "0x00040115") { log.Error(ex.Message); MessageBox.Show("OGCS is not able to run as Outlook is not properly connected to the Exchange server.\r\n" + "Please try again later.", "Application cannot initialise!", MessageBoxButtons.OK, MessageBoxIcon.Exclamation); } else { OGCSexception.Analyse(ex); } throw new ApplicationException(); } catch (System.Exception ex) { OGCSexception.Analyse(ex); log.Fatal("Application unexpectedly terminated!"); MessageBox.Show(ex.Message, "Application unexpectedly terminated!", MessageBoxButtons.OK, MessageBoxIcon.Error); throw new ApplicationException(); } } catch (ApplicationException) { log.Warn("Tidying down any remaining Outlook references, as OGCS crashed out."); try { OutlookCalendar.InstanceConnect = false; OutlookCalendar.Instance.IOutlook.Disconnect(); } catch { } } Splash.CloseMe(); GC.Collect(); GC.WaitForPendingFinalizers(); while (Updater.IsBusy) { Application.DoEvents(); System.Threading.Thread.Sleep(100); } log.Info("Application closed."); }