private static void Main(string[] args) { initialiseFiles(); Application.EnableVisualStyles(); Application.SetCompatibleTextRenderingDefault(false); Splash.ShowMe(); log.Debug("Loading settings from file."); Settings.Load(); isNewVersion(); Updater = new Updater(); 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."); }
private static void Main(string[] args) { Application.EnableVisualStyles(); Application.SetCompatibleTextRenderingDefault(false); try { GoogleOgcs.ErrorReporting.Initialise(); RoamingProfileOGCS = Path.Combine(Environment.GetFolderPath(Environment.SpecialFolder.ApplicationData), Application.ProductName); parseArgumentsAndInitialise(args); Updater.MakeSquirrelAware(); Forms.Splash.ShowMe(); log.Debug("Loading settings from file."); Settings.Load(); Settings.Instance.Proxy.Configure(); Updater = new Updater(); isNewVersion(Program.IsInstalled); Updater.CheckForUpdate(); TimezoneDB.Instance.CheckForUpdate(); try { String startingTab = Settings.Instance.LastSyncDate == new DateTime(0) ? "Help" : null; Application.Run(new Forms.Main(startingTab)); } catch (ApplicationException ex) { String reportError = ex.Message; log.Fatal(reportError); if (ex.InnerException != null) { reportError = ex.InnerException.Message; log.Fatal(reportError); } MessageBox.Show(reportError, "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 (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); } } else { MessageBox.Show(aex.Message, "Application terminated", MessageBoxButtons.OK, MessageBoxIcon.Error); } } catch (System.Exception ex) { OGCSexception.Analyse(ex, true); log.Fatal("Application unexpectedly terminated!"); MessageBox.Show(ex.Message, "Application unexpectedly terminated!", MessageBoxButtons.OK, MessageBoxIcon.Error); } finally { log.Warn("Tidying down any remaining Outlook references, as OGCS crashed out."); OutlookOgcs.Calendar.Disconnect(); Forms.Splash.CloseMe(); GC.Collect(); GC.WaitForPendingFinalizers(); while (Updater != null && 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(Program.IsInstalled); 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 (!OutlookOgcs.Calendar.IsInstanceNull) { OutlookOgcs.Calendar.InstanceConnect = false; OutlookOgcs.Calendar.Instance.IOutlook.Disconnect(); } } catch { } } Splash.CloseMe(); GC.Collect(); GC.WaitForPendingFinalizers(); while (Updater.IsBusy) { Application.DoEvents(); System.Threading.Thread.Sleep(100); } log.Info("Application closed."); }