Exit Windows Phone 7 App in Code

Jan 15, 2011 at 10:31 PM

This has been discussed other places, but I wanted to ask it here. Is there a way to programatically exit a WP7 application? Use case is: on launch I want to prompt them to accept the terms of the trial mode; if not, allow them to quit. I thought I could just call INavigationService.GoBack(), but since it's the default page in the application, CanGoBack is false, which throws System.InvalidOperationException : Cannot go back when CanGoBack is false.

Is that what I'm supposed to do - throw to exit?


Jan 16, 2011 at 12:17 AM

I've heard it recommended that you can create an instance of the Xna Game class and call Exit on it. I think that is the only way. (I'm not sure if that breaks cert guidelines though.)

Jan 16, 2011 at 12:30 AM

I saw that in the comments here http://www.mobilelayers.com/blog/how-to-exit-a-windows-phone-7-application/

as well as the ceritification guideline that would be broken by doing it :)

4.2.5 The application must not call any APIs in the Microsoft.Xna.Framework.Game assembly or the Microsoft.Xna.Framework.Graphics assembly when using any methods from the System.Windows.Controls namespace.

No worries, I'll be clever about showing & hiding controls.