How Can I Catch event when Win8 App Exit
-
16 aprilie 2012 06:55
can i do that ?
Thanks~~~
Toate mesajele
-
16 aprilie 2012 08:32Moderator
Hi CloundToClound,
You can use App's Suspending event. See the App Close section in Application lifecycle for details.
"There's no special event to indicate that the user has closed an app. After an app has been closed by the user, it's suspended and terminated, entering the NotRunning state within about 10 seconds. If an app has registered an event handler for the Suspending | suspending event, it is called when the app is suspended. You can use this event handler to save relevant application and user data to persistent storage.
You should decide how your app behaves when it's activated after being closed by the user. It may make no difference to you whether the app was terminated by Windows or by the user. If your app needs to do something different when it is closed by the user than when it is closed by Windows, the activation event handler can determine whether the app was terminated by the user or by Windows. See the descriptions of ClosedByUser and Terminated states in the docs for the ApplicationExecutionState enumeration.
"
Best regards,
Min Zhu [MSFT]
MSDN Community Support | Feedback to us
- Propus ca răspuns de Horizon_Net 16 aprilie 2012 10:10
- Marcat ca răspuns de Min ZhuMicrosoft Contingent Staff, Moderator 23 aprilie 2012 02:56
-
25 aprilie 2012 11:07
Hi Min,
I use Suspending event to store app data.
But if I close the app (by gesture or alt-f4) and reopen it before the Application.OnSuspended method gets called, this will result in a data loss. App state is NotRunning.
See http://social.msdn.microsoft.com/Forums/en-SG/winappswithcsharp/thread/43da2212-9910-461d-816a-94b479ce9885
Do you have an example how to avoid such data loss?
Regards,
Yury