Mobile Zone is brought to you in partnership with:

.NET Software Engineer, Silverlight, WPF and Windows Phone 7 blogger and enthusiast. Slobodan is a DZone MVB and is not an employee of DZone and has posted 9 posts at DZone. You can read more from them at their website. View Full User Profile

How to Close A Windows Phone App Using Code

08.23.2012
| 1504 views |
  • submit to reddit

In my previous post on how to terminate the Windows Phone application I proposed a solution that is not really in accordance with Windows Phone Marketplace Technical Cerification Requirements (see requirement 5.1.2):

”An application that closes unexpectedly fails certification.”

Even though I’m pretty sure that this requirement is not enforced since my apps use this approach and they were never rejected i decided to present another way.

Some good people suggested in comments of my previous post that you can terminate current application  simply by calling the XNA Game class Exit method like this:

using Microsoft.Xna.Framework;

namespace Roboblob
{
    public class AppLifetimeHelper
    {
        public void CloseApplication()
        {
            new Game().Exit();
        }
    }
}

The downside of this is that you need to add 2 XNA dll’s to your project:

  1. Microsoft.Xna.Framework
  2. Microsoft.Xna.Framework.Game
So there you have both approaches and you can choose which one is better for you until Microsoft exposes standardized way of closing application from code (I hope this will happen in Windows Phone 8 APIs).
Published at DZone with permission of Slobodan Pavkov, author and DZone MVB. (source)

(Note: Opinions expressed in this article and its replies are the opinions of their respective authors and not those of DZone, Inc.)