Jonas Stawski

Everything .NET and More

Debugging Tombstoning with WP7 (Mango)

A new feature of Mango (WP 7.5) is fast app switching, a much needed feature, which every developer should implement in their apps. Before mango, every time the application was deactivated the developer had to maintain state and restore it once the application was re activated. That resulted in very slow transitions between apps and a bad user experience. With fast app switching and the WP 7.1 SDK, the phone maintains all state of the app when it is deactivated and when the user activates it again the app starts right away. It is a much better user experience! Windows Phone tries it’s best to maintain the state, but it is not 100% sure that when the user comes back to your app the state will be preserved, so we can check whether the state is still there and if not restore it ourselves.

   1: private void Application_Activated(object sender, ActivatedEventArgs e)
   2: {
   3:     if (!e.IsApplicationInstancePreserved)
   4:     {
   5:         RestoreState();
   6:     }
   7: }

Very easy to do! This is great, but it doesn’t mean we don’t have to implement tomstoning (please note the article refers to WP 7.0, not 7.1), since we still want to maintain a good user experience, we should restore everything as it was even if the phone wasn’t able to persist the state. You can read the article linked above and it’s second part for a great explanation of how to do so.

The question then arises, how do we debug tombstoning if the application is persisted every time we reactivate the app? We have two options:

  1. Deactivate the app and play around the emulator (or phone) by opening as many apps as you can and pray the phone doesn’t preserve the state when it is reactivated.
  2. Right click on your project file and go to properties. Navigate to the Debug tab and check the “Tombstone upon deactivation while debugging”.


As you might imagine option 2 is the recommended approach as it is probably a much more efficient way to debug tombstoning! Next time your application is activated e.IsApplicationInstancePreserved will be false.

Happy Tombstoning!

Comments (1) -

This is the third article in a row I've read on your site while I'm working on my latest app. This is all great stuff Jonas. Thanks for posting this great content.


Add comment