Example #1
0
        /// <summary>
        /// Implements the logic to start up the desktop by running the GUI toolkit and creating the application view.
        /// </summary>
        private void Run(string[] args)
        {
            // load gui toolkit
            try
            {
                _guiToolkit = (IGuiToolkit)(new GuiToolkitExtensionPoint()).CreateExtension();
            }
            catch (Exception ex)
            {
                ExceptionHandler.ReportUnhandled(ex);
                return;
            }

            _guiToolkit.Started += delegate
            {
                // load application view
                try
                {
                    _synchronizationContext = SynchronizationContext.Current;
                    _view = (IApplicationView)ViewFactory.CreateAssociatedView(this.GetType());
                }
                catch (Exception ex)
                {
                    ExceptionHandler.ReportUnhandled(ex);
                    TerminateGuiToolkit();
                    return;
                }

                // initialize
                if (!Initialize(args))
                {
                    TerminateGuiToolkit();
                    return;
                }

                _initialized = true;

                PhoneHome.Startup();

                // now that the desktop is fully initialized, take advantage of idle time to
                // load any outstanding plugins
                Platform.PluginManager.EnableBackgroundAssemblyLoading(true);
            };

            // init windows collection
            _windows             = new DesktopWindowCollection(this);
            _windows.ItemClosed += delegate
            {
                // terminate the app when the window count goes to 0 if the app isn't already quitting
                if (_windows.Count == 0 && !IsQuitting)
                {
                    Quit(false);
                }
            };


            // start message pump - this will block until _guiToolkit.Terminate() is called
            _guiToolkit.Run();
        }
Example #2
0
        /// <summary>
        /// Implements the logic to terminate the desktop, including closing all windows and terminating the session.
        /// </summary>
        /// <returns>True if the application is really going to terminate, false otherwise.</returns>
        private void DoQuit(bool force)
        {
            if (IsQuitting)
            {
                return;
            }

            PhoneHome.ShutDown();

            if (!force)
            {
                _quitState = QuitState.QuittingNormally;
                if (!CloseAllWindows())
                {
                    _quitState = QuitState.NotQuitting;
                    return;
                }

                // send quitting event
                QuittingEventArgs args = new QuittingEventArgs();
                OnQuitting(args);
            }
            else
            {
                _quitState = QuitState.QuittingForcefully;
            }

            try
            {
                SessionManager.Current.TerminateSession();
            }
            catch (Exception e)
            {
                Platform.Log(LogLevel.Error, e);
            }

            // shut down the GUI message loop
            TerminateGuiToolkit();
        }