pratpor
pratpor

Reputation: 2104

On exit event for Windows Phone 8

How can I register an OnExit Event for my Windows Phone 8 app to do some tasks before user exits Application.

I tried using:

Application.Current.Exit

But Visual Studio says it wont be called for Windows Phone. Any Help?

Thanks

Upvotes: 1

Views: 726

Answers (2)

lisp
lisp

Reputation: 4198

You have a PhoneApplicationService.Closing event. In the autogenerated App.xaml.cs you should already have a hooked-up Application_Closing handler. However, you should not use it, as:

If your app is terminated by the operating system while it is not in the foreground, the Closing event will not be raised. Your app can rely on receiving the Deactivated event, but not Closing. For this reason, you should perform all essential cleanup and state maintenance tasks in the Deactivated event handler.

Put your tasks in the auto-generated Application_Deactivated method.

Upvotes: 4

robwirving
robwirving

Reputation: 1798

I'm assuming this is a Windows Phone 8.0 Silverlight Application since you didn't state otherwise.

In your App.xaml.cs there should be an Application_Closing() event. You'd want to run these tasks here. Just beware as you only have a few seconds to run code before the OS kills your process.

Upvotes: 1

Related Questions