简体   繁体   English

如何在Windows Store应用程序中正确保留数据

[英]How to persist data correctly in Windows Store app

I want to save the data of Windows Store app to the file system (local folder) on suspension of the the app. 我想在应用程序暂停时将Windows Store应用程序的数据保存到文件系统(本地文件夹)中。 On start of the app the persisted data is loaded from the file system and displayed in the app. 在应用程序启动时,持久性数据将从文件系统加载并显示在应用程序中。 This is working fine until the user closes the app and immediately restarts the app (because the suspension of the first app instance isn't yet finished). 在用户关闭该应用程序并立即重新启动该应用程序之前,这是正常的(因为第一个应用程序实例的暂停尚未完成)。

Now, I'm not sure whether 现在,我不确定

  1. I have to persist the data in another way or 我必须以其他方式保留数据或
  2. I can wait until any other instance of my app is completely suspended. 我可以等到我的应用程序的任何其他实例完全挂起。

Do you have any suggestions? 你有什么建议吗?

The problem is that after a close it take a few second before the suspending even is actually call and when the user restart, the previous instance of the app is killed so the suspending event is not even called and there is not much you can do to prevent that. 问题是,关闭后需要花费几秒钟才能真正调用暂停甚至连接,并且当用户重新启动时,该应用程序的前一个实例被杀死,因此甚至没有调用暂停事件,并且您无能为力防止这种情况。
The recommendation is to save data incrementally as anyway the suspended event only have 5 seconds to complete. 建议以增量方式保存数据,因为无论如何暂停事件仅需5秒即可完成。

The other possibility is to make your app target windows 8.1 as this issue as been fixed in windows 8.1 : 另一种可能性是使您的应用程序以Windows 8.1为目标,因为此问题已在Windows 8.1中解决

In Windows 8.1 Preview, if the user closes an app and then immediately restarts it, the closed app is given up to five seconds to complete its termination before it restarts. 在Windows 8.1预览版中,如果用户关闭了某个应用程序然后立即将其重新启动,则关闭的应用程序将有最多五秒钟的时间来完成其终止,然后再重新启动。 In Windows 8, the app terminates immediately upon restart. 在Windows 8中,该应用程序在重启后立即终止。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM