Please note that as of October 24, 2014, the Nokia Developer Wiki will no longer be accepting user contributions, including new entries, edits and comments, as we begin transitioning to our new home, in the Windows Phone Development Wiki. We plan to move over the majority of the existing entries. Thanks for all your past and future contributions.

How to terminate a Windows Phone app

From Wiki
Jump to: navigation, search

This article explains how to terminate a Windows Phone app programmatically.

SignpostIcon XAML 40.png
WP Metro Icon WP8.png
SignpostIcon WP7 70px.png
Article Metadata
Tested with
SDK: Windows Phone 8.0 SDK
Devices(s): Nokia Lumia 920, WP7.1 Emulator
Created: Kunal Chowdhury (04 Sep 2013)
Last edited: hamishwillee (22 Jan 2014)



The Windows Phone app lifecyle is such that apps are typically terminated by the user pressing the back button, or pushed into a dormant state (and perhaps later tombstoned) if the user activates another app from the start screen.

Even though it is not common practice, at times, one may want to terminate the application programmatically. There are a number of cases where this is necessary - for example where the app has had an exception and you cannot guarantee that it is in a "safe" state you may wish to terminate after logging the issue. Other use cases might include security applications where you don't want the user to be able to enter further data/continue using the app.

Windows Phone 8

To terminate the application completely, you just have to call the following API:


This will terminate the running application completely. The place to call this API may vary depending upon your requirement.

Tip.pngTip: Make sure to save important data before calling this API. No lifecycle events will be fired following termination

Windows Phone 7

The Game::Exit() method (from Microsoft.Xna.Framework namespace) can be used to programmatically exit an app on WP7. This can be used even in non-XNA apps.

Warning.pngWarning: An alternative is to raise an exception which your app does not handle. This approach is not recommended because app crashes affect your App Store ranking, and because it may lead to certification issues.

Cross-version method for terminating an app on WP7 and WP8

Unfortunately neither approach compiles on both versions, so to get the same code to work on both platforms requires reflection. The code below compiles and works on both Windows Phone 7 and Windows Phone 8.

Tip.pngTip: If you already know that your app will only be targeting WP8 it is better to use Application.Current.Terminate() directly.

        private static void Terminate()
if (Environment.OSVersion.Version.Major < 8)//try to load XNA assemblies (only working on WP7)
System.Reflection.Assembly asmb = System.Reflection.Assembly.Load("Microsoft.Xna.Framework, Version=, Culture=neutral, PublicKeyToken=842cf8be1de50553");
asmb = System.Reflection.Assembly.Load("Microsoft.Xna.Framework.Game, Version=, Culture=neutral, PublicKeyToken=842cf8be1de50553");
Type type = asmb.GetType("Microsoft.Xna.Framework.Game");
object obj = type.GetConstructor(new Type[] { }).Invoke(new object[] { });
type.GetMethod("Exit").Invoke(obj, new object[] { });
else// => WP8
Type type = Application.Current.GetType();
type.GetMethod("Terminate").Invoke(Application.Current, new object[] { });

Related Links

Confirming that the user wants to leave the app

This page was last modified on 22 January 2014, at 04:36.
358 page views in the last 30 days.