Derik Whittaker

Syndication

News


Exiting out of a WP7 Application

*****
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:

  1. Add reference to Microsoft.Xna.Framework.Game
  2. 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,


Posted 10-19-2010 8:26 AM by Derik Whittaker
Filed under: ,

[Advertisement]

Comments

Rene Schulte wrote re: Exiting out of a WP7 Application
on 10-19-2010 11:27 AM

If you do this, your Silverlight app will fail the Marketplace certification.

See the "Windows Phone 7 Application Certification Requirements"

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.

Daniel Vaughan wrote re: Exiting out of a WP7 Application
on 10-19-2010 11:27 AM

Hi Derik,

I'm afraid that this will violate the Marketplace Certification Requirements.

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.

Derik Whittaker wrote re: Exiting out of a WP7 Application
on 10-19-2010 12:48 PM

@Randy & @Daniel,

SHIT.... I guess i missed that while reading the specs.

Really pisses me off that MS thinks exiting an app is not 'normal' and they did not add that feature.

James ashley wrote re: Exiting out of a WP7 Application
on 10-19-2010 3:06 PM

Derik,

As it stands, I don't think anyone is sure if throwing a custom exception will get through Marketplace certification (I'm obviously hoping it will).  If it doesn't, it may be the case that there just is no valid way to programmatically exit a Silverlight app for the phone.  

Derik Whittaker wrote re: Exiting out of a WP7 Application
on 10-19-2010 3:52 PM

James,

I am a TAP member for WP7 so I just posted this question to MS.  Lets see if they respond

Mark Knell wrote re: Exiting out of a WP7 Application
on 10-19-2010 6:37 PM

"Exiting out"?   In which other directions do you usually exit?

Heh.

Jstun wrote re: Exiting out of a WP7 Application
on 12-01-2010 1:59 PM

You can also pass an invalid path to NavigationService.Navigate which would throw the exception. Just wanted to give a more concrete example.

About The CodeBetter.Com Blog Network
CodeBetter.Com FAQ

Our Mission

Advertisers should contact Brendan

Subscribe
Google Reader or Homepage

del.icio.us CodeBetter.com Latest Items
Add to My Yahoo!
Subscribe with Bloglines
Subscribe in NewsGator Online
Subscribe with myFeedster
Add to My AOL
Furl CodeBetter.com Latest Items
Subscribe in Rojo

Member Projects
DimeCasts.Net - Derik Whittaker

Friends of Devlicio.us
Red-Gate Tools For SQL and .NET

NDepend

SlickEdit
 
SmartInspect .NET Logging
NGEDIT: ViEmu and Codekana
LiteAccounting.Com
DevExpress
Fixx
NHibernate Profiler
Unfuddle
Balsamiq Mockups
Scrumy
JetBrains - ReSharper
Umbraco
NServiceBus
RavenDb
Web Sequence Diagrams
Ducksboard<-- NEW Friend!

 



Site Copyright © 2007 CodeBetter.Com
Content Copyright Individual Bloggers

 

Community Server (Commercial Edition)