Exemplo n.º 1
0
        // This method saves the application state before entering background state. It fires the event OnBackgroundEntering to collect
        // state data from the current subscriber and saves it to the local storage.
        public async Task <bool> SaveStateAsync()
        {
            if (OnBackgroundEntering == null)
            {
                return(false);
            }

            try
            {
                var suspensionState = new SuspensionState()
                {
                    SuspensionDate = DateTime.Now
                };

                var target = OnBackgroundEntering?.Target.GetType();
                var onBackgroundEnteringArgs = new SuspendAndResumeArgs(suspensionState, target);

                OnBackgroundEntering?.Invoke(this, onBackgroundEnteringArgs);

                await ApplicationData.Current.LocalFolder.SaveAsync(StateFilename, onBackgroundEnteringArgs);

                return(true);
            }
            catch (Exception)
            {
                // TODO WTS: Save state can fail in rare conditions, please handle exceptions as appropriate to your scenario.
                return(false);
            }
        }
Exemplo n.º 2
0
 public SuspendAndResumeArgs(SuspensionState suspensionState, Type target)
 {
     SuspensionState = suspensionState;
     Target          = target;
 }