by brad
30. September 2010 13:38
The last few tips have been on activating, launching, and deactivating. Today we’ll cover Closing.
The Closing event marks the death of an instance of your application. While an application that has been deactivated can be activated and come back, and application instance that has been closed is kaput. If the application is opened again, it will be a new instance.
According to MSDN, there is only one way that your application can be closed: the user is on the first page of your application and presses the hardware Back button. Any other action that makes your application step into the background (pressing the Start button, opening a launcher, the phone timing out) will raise the Deactivating event, not the Closing event.
You should save any persistent data in the Closing event. Even if you are saving persistent data in the Deactivating event (which you should), you’ll need to do it as well in the Closing event because the Deactivating event will not be called before the Closing event. There is no need to save transient state because an application instance that is closing will not come back. The next run of the application will be a new instance.
Other Resources
More Tips