コード例 #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);
            }
        }
        public void SaveStateAsync()
        {
            var suspensionState = new SuspensionState()
            {
                SuspensionDate = DateTime.Now
            };

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

            OnBackgroundEntering?.Invoke(this, onBackgroundEnteringArgs);
        }
コード例 #3
0
        public async Task SaveStateAsync()
        {
            var suspensionState = new SuspensionState()
            {
                SuspensionDate = DateTime.Now
            };

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

            OnBackgroundEntering?.Invoke(this, onBackgroundEnteringArgs);

            await ApplicationData.Current.LocalFolder.SaveAsync(stateFilename, onBackgroundEnteringArgs);
        }
コード例 #4
0
        public async Task SaveStateAsync()
        {
            // #TODO Update to make sure states get saved properly with multiple instances
            var suspensionState = new SuspensionState()
            {
                SuspensionDate = DateTime.Now
            };

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

            OnBackgroundEntering?.Invoke(this, onBackgroundEnteringArgs);

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