Example #1
0
        /// <summary>
        /// Invoked when the application is about to start when it's launched normally by end user.
        /// Override this method to implement state restoration and other application-level initialization.
        /// </summary>
        /// <param name="args"></param>
        protected override async void OnApplicationStarting(LaunchActivatedEventArgs args)
        {
            // By default, RootFrame will automatically instantiate a new Frame object when it's accessed for the first time
            // To specify a custom frame, please override the RootFrame property.

            // Obtains the registered application state service
            IntersoftCore.IApplicationStateService stateService = this.GetService <IntersoftCore.IApplicationStateService>();

            // Associate the frame with an ApplicationStateService key
            stateService.RegisterFrame(this.RootFrame, "AppFrame");

            if (args.PreviousExecutionState == ApplicationExecutionState.Terminated)
            {
                // Restore the saved session state only when appropriate
                try
                {
                    await stateService.RestoreAsync();
                }
                catch (ApplicationStateServiceException)
                {
                    //Something went wrong restoring state.
                    //Assume there is no state and continue
                }
            }
        }
Example #2
0
        /// <summary>
        /// Invoked when application execution is being suspended.  Application state is saved
        /// without knowing whether the application will be terminated or resumed with the contents
        /// of memory still intact.
        /// </summary>
        /// <param name="sender">The source of the suspend request.</param>
        /// <param name="e">Details about the suspend request.</param>
        protected override async void OnSuspending(SuspendingEventArgs args)
        {
            // Obtains the registered application state service
            IntersoftCore.IApplicationStateService stateService = this.GetService <IntersoftCore.IApplicationStateService>();

            var deferral = args.SuspendingOperation.GetDeferral();
            await stateService.SaveAsync();

            deferral.Complete();
        }