How to simulate a Terminated PreviousExecutionState in a Windows 10 app


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…


…which leads to a ClosedByUser state:


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!