public PrismApplicationBase() { InternalInitialize(); (this as IPrismApplicationEvents).WindowCreated += (s, e) => { GestureService.SetupForCurrentView(e.Window.CoreWindow); }; base.Suspending += async(s, e) => { if (ApplicationData.Current.LocalSettings.Values.ContainsKey("Suspend_Data")) { ApplicationData.Current.LocalSettings.Values.Remove("Suspend_Data"); } ApplicationData.Current.LocalSettings.Values.Add("Suspend_Data", DateTime.Now.ToString()); var deferral = e.SuspendingOperation.GetDeferral(); try { OnSuspending(); await OnSuspendingAsync(); } finally { deferral.Complete(); } }; base.Resuming += async(s, e) => { await InternalStartAsync(new StartArgs(ResumeArgs.Create(ApplicationExecutionState.Suspended), StartKinds.Resume)); }; }
public virtual bool IsResuming(StartArgs startArgs, out ResumeArgs resumeArgs) { if (WasTerminated() && WasSuspended()) { resumeArgs = new ResumeArgs { PreviousExecutionState = ApplicationExecutionState.Terminated, SuspendDate = GetSuspendDate(), }; return(true); } resumeArgs = null; return(false); bool WasTerminated() { return(startArgs.Arguments is ILaunchActivatedEventArgs e && e.PreviousExecutionState == ApplicationExecutionState.Terminated); } bool WasSuspended() { return(ApplicationData.Current.LocalSettings.Values.ContainsKey("Suspend_Data")); } }
private static void TestResuming(StartArgs startArgs) { if (startArgs.Arguments is ILaunchActivatedEventArgs e && e.PreviousExecutionState == ApplicationExecutionState.Terminated) { if (ApplicationData.Current.LocalSettings.Values.ContainsKey("Suspend_Data")) { startArgs.Arguments = ResumeArgs.Create(ApplicationExecutionState.Terminated); startArgs.StartKind = StartKinds.Resume; } } }
public static ResumeArgs Create(ApplicationExecutionState state) { var args = new ResumeArgs { PreviousExecutionState = state }; if (ApplicationData.Current.LocalSettings.Values.TryGetValue("Suspend_Data", out var value) && value is DateTime date) { args.SuspensionDate = date; } ApplicationData.Current.LocalSettings.Values.Remove("Suspend_Data"); return(args); }
public PrismApplicationBase() { InternalInitialize(); _logger.Log("[App.Constructor()]", Category.Info, Priority.None); CoreApplication.Exiting += (s, e) => { var stopArgs = new StopArgs(StopKind.CoreApplicationExiting) { CoreApplicationEventArgs = e }; OnStop(stopArgs); OnStopAsync(stopArgs); }; WindowService.WindowCreatedCallBacks.Add(Guid.Empty, args => { WindowService.WindowCreatedCallBacks.Remove(Guid.Empty); args.Window.Closed += (s, e) => { OnStop(new StopArgs(StopKind.CoreWindowClosed) { CoreWindowEventArgs = e }); OnStopAsync(new StopArgs(StopKind.CoreWindowClosed) { CoreWindowEventArgs = e }).RunSynchronously(); }; SystemNavigationManagerPreview.GetForCurrentView().CloseRequested += async(s, e) => { var deferral = e.GetDeferral(); try { OnStop(new StopArgs(StopKind.CloseRequested) { CloseRequestedPreviewEventArgs = e }); await OnStopAsync(new StopArgs(StopKind.CloseRequested) { CloseRequestedPreviewEventArgs = e }); } finally { deferral.Complete(); } }; }); base.Suspending += async(s, e) => { new SuspensionUtilities().SetSuspendDate(DateTime.Now); var deferral = e.SuspendingOperation.GetDeferral(); try { var stopArgs = new StopArgs(StopKind.Suspending) { SuspendingEventArgs = e }; OnStop(stopArgs); await OnStopAsync(stopArgs); } finally { deferral.Complete(); } }; base.Resuming += async(s, e) => { var resumeArgs = new ResumeArgs { PreviousExecutionState = ApplicationExecutionState.Suspended, }; var startArgs = new StartArgs(resumeArgs, StartKinds.ResumeInMemory); await InternalStartAsync(startArgs); }; }