Exemplo n.º 1
0
 /// <summary>
 /// Publish a unexpected exception to the user.
 /// Retry/Ignore/Cancel dialog is displayed, if <c>resumable</c> is true.
 /// </summary>
 /// <param name="ex">Exception to report</param>
 /// <param name="resumable">Set this to true, if the exception is resumable and react
 /// to the DialogResult returned.</param>
 /// <returns>Retry/Ignore/Cancel DialogResults</returns>
 public static DialogResult PublishException(Exception ex, bool resumable)
 {
     return(ApplicationExceptionHandler.ShowExceptionDialog(ex, resumable));
 }
Exemplo n.º 2
0
        private static int Main(string[] args)
        {
            bool running = true;

            Application.EnableVisualStyles();
            Application.SetCompatibleTextRenderingDefault(false);
            // This might fix the SEHException raised sometimes. See issue:
            // https://sourceforge.net/tracker/?func=detail&aid=2335753&group_id=96589&atid=615248
            Application.DoEvents();

            // child threads should impersonate the current windows user
            AppDomain.CurrentDomain.SetPrincipalPolicy(System.Security.Principal.PrincipalPolicy.WindowsPrincipal);

            /* setup handler for unhandled exceptions in non-debug modes */
            // Allow exceptions to be unhandled so they break in the debugger
#if !DEBUG
            ApplicationExceptionHandler eh = new ApplicationExceptionHandler();

            AppDomain.CurrentDomain.UnhandledException += eh.OnAppDomainException;
#endif

#if DEBUG && TEST_I18N_THISCULTURE
            Thread.CurrentThread.CurrentUICulture = new System.Globalization.CultureInfo(new I18NTestCulture().Culture);
            Thread.CurrentThread.CurrentCulture   = Thread.CurrentThread.CurrentUICulture;
#endif

            FormWindowState initialStartupState = Win32.GetStartupWindowState();
            // if you want to debug the minimzed startup (cannot be configured in VS.IDE),
            // comment out the line above and uncomment the next one:
            //FormWindowState initialStartupState =  FormWindowState.Minimized;

            RssBanditApplication  appInstance = new RssBanditApplication();
            OtherInstanceCallback callback    = appInstance.OnOtherInstance;
            try
            {
                running = InitialInstanceActivator.Activate(appInstance, callback, args);
            }
            catch (Exception /* ex */)
            {
                //_log.Error(ex); /* other instance is probably still running */
            }
            //_log.Info("Application v" + RssBanditApplication.VersionLong + " started, running instance is " + running);

            RssBanditApplication.StaticInit(appInstance);
            if (!running)
            {
                // init to system default:
                RssBanditApplication.SharedCulture   = CultureInfo.CurrentCulture;
                RssBanditApplication.SharedUICulture = CultureInfo.CurrentUICulture;

                if (appInstance.HandleCommandLineArgs(args))
                {
                    if (!string.IsNullOrEmpty(appInstance.CommandLineArgs.LocalCulture))
                    {
                        try
                        {
                            RssBanditApplication.SharedUICulture =
                                CultureInfo.CreateSpecificCulture(appInstance.CommandLineArgs.LocalCulture);
                            RssBanditApplication.SharedCulture = RssBanditApplication.SharedUICulture;
                        }
                        catch (Exception ex)
                        {
                            appInstance.MessageError(String.Format(
                                                         SR.ExceptionProcessCommandlineCulture,
                                                         appInstance.CommandLineArgs.LocalCulture,
                                                         ex.Message));
                        }
                    }

                    // take over customized cultures to current main thread:
                    Thread.CurrentThread.CurrentCulture   = RssBanditApplication.SharedCulture;
                    Thread.CurrentThread.CurrentUICulture = RssBanditApplication.SharedUICulture;

                    if (!appInstance.CommandLineArgs.StartInTaskbarNotificationAreaOnly &&
                        initialStartupState != FormWindowState.Minimized)
                    {
                        // no splash, if start option is tray only or minimized
                        Splash.Show(SR.AppLoadStateLoading,
                                    String.Format(String.IsNullOrEmpty(RssBanditApplication.versionPostfix) ? "v{0}": "v{0} {1}",
                                                  RssBanditApplication.Version, RssBanditApplication.versionPostfix)
                                    );
                    }

                    if (appInstance.Init())
                    {
                        // does also run the windows event loop:
                        appInstance.StartMainGui(initialStartupState);
                        Splash.Close();
                    }
                    else
                    {
                        return(3); // init error
                    }
                    return(0);     // OK
                }
                return(2);         // CommandLine error
            }
            return(1);             // other running instance
        }