简体   繁体   English

我是否需要在Windows Phone应用程序中调用IsolatedStorageSettings.Save方法?

[英]Do I need to call IsolatedStorageSettings.Save method in windows phone application?

From the remarks section of IsolatedStorageSettings.Save Method page: IsolatedStorageSettings.Save方法页面的备注部分:

Data written to the IsolatedStorageSettings object is saved when the application that uses the class is closed. 当关闭使用该类的应用程序时,将保存写入IsolatedStorageSettings对象的数据。 This can occur when the user closes the Web browser, refreshes a page, or browses away from the page. 当用户关闭Web浏览器,刷新页面或浏览页面时,可能会发生这种情况。 If you want your application to write to isolated storage immediately, you can call the Save method in application code. 如果您希望应用程序立即写入隔离存储,则可以在应用程序代码中调用Save方法。

So, I can never call the Save method and every setting will be in safety. 所以,我永远不能调用Save方法,每个设置都是安全的。 I'm just curious in what usecases should I use the Save method? 我只是好奇我应该使用Save方法?

You have to call IsolatedStorageSettings.Save yourself. 你必须自己调用IsolatedStorageSettings.Save As mentioned in the 'Tips and Warnings' section at the bottom of the class reference page , you have to save it yourself in order to make sure it's written to the file. 类参考页面底部的“提示和警告”部分所述,您必须自己保存它以确保将其写入文件。

The IsolatedStorageSettings class is not automatically saved to disk when values are written. 写入值时,IsolatedStorageSettings类不会自动保存到磁盘。 Saves are done in a finalizer, which is usually but not always run when the application shuts down. 保存在终结器中完成,通常但不总是在应用程序关闭时运行。 To ensure saves are actually performed we need to call the Save method after each write or set of writes. 为确保实际执行保存,我们需要在每次写入或写入一组后调用Save方法。

Here is the documentation for the IsolatedStorageSettings.Save method dated February 14, 2014: 以下是2014年2月14日的IsolatedStorageSettings.Save方法的文档:

http://msdn.microsoft.com/en-us/library/windowsphone/develop/system.io.isolatedstorage.isolatedstoragesettings.save(v=vs.105).aspx http://msdn.microsoft.com/en-us/library/windowsphone/develop/system.io.isolatedstorage.isolatedstoragesettings.save(v=vs.105).aspx

And an excerpt the from it (see the Caution): 并从中摘录(见警告):

However you don't have to call the Save method on Windows Phone. 但是,您不必在Windows Phone上调用Save方法。 The data that you store in the IsolatedStorageSettings object is saved automatically. 存储在IsolatedStorageSettings对象中的数据将自动保存。

My dev experience also proves that - the settings are saved automatically without the need to call the Save method explicitly. 我的开发经验也证明 - 自动保存设置,而无需显式调用Save方法。 But note that it happens only when you close the whole app, excatly as it is stated in MSDN: 但请注意,只有当您关闭整个应用程序时才会发生这种情况,如MSDN中所说:

Data written to the IsolatedStorageSettings object is saved when the application that uses the class is closed. 当关闭使用该类的应用程序时,将保存写入IsolatedStorageSettings对象的数据。 If you want your application to write to isolated storage immediately, you can call the Save method in application code. 如果您希望应用程序立即写入隔离存储,则可以在应用程序代码中调用Save方法。

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

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