protected virtual bool OnApplicationShouldRestore(CrystalApplicationShouldRestoreEventArgs args) { //restore if the suspension file is less than 5 hours old. return(args.SuspensionFileDate != null ? (args.SuspensionFileDate - DateTime.Now) < TimeSpan.FromHours(5) : true); }
private async Task InitializeRootFrameAsync(IActivatedEventArgs e) { InitializeIoC(); var rootFrame = Window.Current.Content as Frame; // Do not repeat app initialization when the Window already has content, // just ensure that the window is active if (rootFrame == null) { // Create a Frame to act as the navigation context and navigate to the first page rootFrame = new Frame(); //rootFrame.NavigationFailed += OnNavigationFailed; // Place the frame in the current Window Window.Current.Content = rootFrame; var navManager = new NavigationManager(this); var navService = new FrameNavigationService(rootFrame, navManager); navService.NavigationLevel = FrameLevel.One; navManager.RootNavigationService = navService; InitializeNavigation(navManager); } await OnApplicationInitializedAsync(); if (e.PreviousExecutionState == ApplicationExecutionState.Terminated) { //Resurrection! IStorageItem suspensionStateFileItem = await CrystalApplication.CrystalDataFolder.TryGetItemAsync(PreservationManager.SuspensionStateFileName); if (suspensionStateFileItem != null) { StorageFile suspensionStateFile = (StorageFile)suspensionStateFileItem; var eventArgs = new CrystalApplicationShouldRestoreEventArgs(); eventArgs.SuspensionFileDate = suspensionStateFile.DateCreated; if (OnApplicationShouldRestore(eventArgs)) { if (await PreservationManager.RestoreAsync() == true) { //navService.HandleTerminationReload(); //todo handle multiple windows in this case. try { await suspensionStateFile.DeleteAsync(); } catch (Exception) { } IsRestored = true; if (Restored != null) { Restored(this, EventArgs.Empty); } } } } } // Ensure the current window is active //Window.Current.Activate(); HandleBackNavigation(); WindowManager.GetStatusManagerForCurrentView().Initialize(); }