Windows Store App : Debugging store app in suspend / resume / suspend and shutdown states

Note: This post is old, Microsoft have released "Universal Windows Platform" UWP Apps and this content may or may not apply to that framework.

Windows Store Apps gets installed and runs on Windows 8, it can be a desktop, laptop or a limited resource based tablet. Windows 8 manages all the running the applications in a better way to manage the available memory by introducing the Application Lifecycle model.

This life cycle model design helps to automatically manage the application state running for the user. This helps in better memory management and power and battery consumption.

This means more efforts on developer end (not in a scary way). If your application cares for users input data (which we usually care) we need to make sure that in any of the above life cycle event we capture user data and current preferences and present the same when user comes back accordingly. This gives the user feeling as the application is always running and he should not fear to loose his inputs if he switch to other app.

The execution of the application can be in one of the following states:

  • Not Running
  • Activated
  • Running
  • Suspended / suspending
  • Resumed / Resuming
  • Terminating / terminated

Now that you know about application life cycle events / states and have written code to handle all the life cycle or execution state events, you want to test the same to ensure that you are knocking the right door. This is part where it becomes difficult at times to debug the Suspending / Suspended state (you think).

From information on App Suspend at MSDN, you learn that the application is given a strict maximum time of only 5 seconds to save states before the application enters the suspended state. It clearly states that –

If an app does not return from the suspending event within 5 seconds, Windows assumes that the app has stopped responding and terminates it.

Debugging also becomes difficult if you want to test the terminated / terminating state.

In Visual Studio 2012 (also Express 2012 for Windows 8) comes with new set of debugging commands to simulate the above states for your application and debug them in better way.

Enable debug location

Debug commands:

  1. Suspend – This debug command changes the state of application to suspended once the suspending event is handled.

  2. Resume – It resumes the application by bringing the application in front and changing the state of the application to running state.

  3. Suspend and shutdown – This command will behave the same as suspend command and once the application enters the suspended state, it terminates the application and exits from debugging.

Till recent release of Visual studio this debug options are not visible / enabled by default. You can enable it by > Right click on toolbar > Select “Debug location”

Enable debug location