ApplicationLifetimeSample.Utlitities.NavigationSuspensionManager.SetNavigationStateAsync C# (CSharp) Метод

SetNavigationStateAsync() публичный Метод

public SetNavigationStateAsync ( string navigationState ) : System.Threading.Tasks.Task
navigationState string
Результат System.Threading.Tasks.Task
        public async Task SetNavigationStateAsync(string navigationState)
        {
            StorageFile file = await ApplicationData.Current.LocalCacheFolder.CreateFileAsync(NavigationStateFile, CreationCollisionOption.ReplaceExisting);
            Stream stream = await file.OpenStreamForWriteAsync();
            using (var writer = new StreamWriter(stream))
            {
                await writer.WriteLineAsync(navigationState);
            }
        }

Usage Example

        /// <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>
        private async void OnSuspending(object sender, SuspendingEventArgs e)
        {
            var deferral = e.SuspendingOperation.GetDeferral();
            var frame = Window.Current.Content as Frame;
            if (frame?.BackStackDepth >= 1)
            {
                var suspensionManager = new NavigationSuspensionManager();
                string navigationState = frame.GetNavigationState();
                if (navigationState != null)
                {
                    await suspensionManager.SetNavigationStateAsync(navigationState);
                }
            }

            await DataManager.Instance.SaveTempSessionAsync();

            deferral.Complete();
        }