如何在Windows Store App Close上保存数据? [英] How to save data on Windows Store App Close?

查看:40
本文介绍了如何在Windows Store App Close上保存数据?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有以下问题.当用户关闭Windows应用商店应用程序时,我想要保存数据的文本文件.

i have the following problem. When the user closes the Windows store app, i want a text file with data to be saved.

我应该写什么方法,以便在关闭应用程序时保存文件?

What method should i write so that when closing the app a file gets saved ?

推荐答案

本文描述Windows应用商店应用程序的生命周期.

This article describes the application lifecycle of a Windows Store App.

如果只看第一个数字,就会发现只有3个与应用程序生命周期相关的事件:

If you look at the very first figure, you can see that there are only 3 events related to application lifecycle:

  1. 已激活-在程序首次启动时引发
  2. 已暂停-在程序被暂停(即用户返回开始屏幕"或其他应用)时触发
  3. 恢复-在程序从挂起状态唤醒时触发.
  1. Activated - Raised when program first starts
  2. Suspended - Raised when program is suspended (i.e. the user returns to the Start Screen or another app)
  3. Resuming - Raised when the program is awakened from its suspended state.

第四个转换-到未运行"状态的转换-没有此类通知事件.原因是:您并不真正知道应用程序何时完全关闭.您也不应该-Microsoft希望您在从运行"到挂起"的过渡中执行所有的状态节省逻辑.这样,他们可以在必要时释放资源.

The fourth transition - the one to the "Not Running" state - has no such notification event. The reason is: you don't really know when the app will fully close. Nor should you - Microsoft wants you to perform all of your state-saving logic in the transition from "Running" to "Suspended." In this way, they can free up resources when they deem necessary.

即使用户强迫程序终止(通过右键单击该程序并从任务菜单中选择关闭"),您也将在终止程序之前的10秒钟内进入已暂停"状态.因此,您可以放心,始终可以执行您的状态保存逻辑.

Even if the user forces the program to terminate (by right-clicking it and selecting "Close" from the task menu), you will enter the "Suspended" state for exactly 10 seconds before the program is terminated. So you can rest easy that your state-saving logic will always be executed.

这篇关于如何在Windows Store App Close上保存数据?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆