How to simulate a Terminated PreviousExecutionState in a Windows 10 app

Testing this can be tricky however. I tried using the Lifecycle Events in the debug toolbar and clicked Suspend and shutdown...

terminating

After the Windows OS suspends and terminates a WinRT app, the action we (developers) have to take when the user activates the app again, is restore the session data. In the OnLaunched event, you can check the PreviousExecutionState like this:

protected override void OnLaunched(LaunchActivatedEventArgs e) {
	.
	.
	.
	if (e.PreviousExecutionState == ApplicationExecutionState.Terminated) {
		//TODO: Load state from previously suspended application
	}
}

Testing this can be tricky however. I tried using the Lifecycle Events in the debug toolbar and clicked Suspend and shutdown…

sas

…which leads to a ClosedByUser state:

cbu

Simulating the ApplicationExecutionState.Terminated

To simulate a PreviousExecutionState == ApplicationExecutionState.Terminated you can try the following:

The breakpoint is hit and the status is:

application state terminated

I hope this helps you too!

Written by Loek van den Ouweland on June 01, 2015. Questions regarding this artice? You can send them to the address below.
By using this site, you acknowledge that you have read and understand our Cookie and Privacy Policy.