NOTE – As readers pointed out this method will NOT allow your application to be accepted into the Marketplace (damn you MS) so please do not follow the original advice here (crossed out below).
When building a WP7 Silverlight application, not a Silverlight Game or XNA Game, there are some very valid scenarios when you want to explicitly kill/exit your application. Unfortunately there is no built in mechanism in the Silverlight libraries would facilitate this for you. However, this ability does exist in the XNA framework (exiting a game in XNA is a very valid and common activity) and because it is in the XNA framework you can use it in your silverlight application.
To Exit your Silverlight application you need to do 2 things:
Add reference to Microsoft.Xna.Framework.Game
Run this line of code - new Game().Exit();
UPDATE – Here is another solution which will work and allow you to be accepted into the Marketplace – Throwing Exceptions to Exit your Silverlight App
Peter Torr has a great blog post here about all the various scenarios you may want to exit a WP7 application and each of their side affects. I would encourage you to read his post to learn more about this topic.
Till next time,
10-19-2010 8:26 AM