简体   繁体   中英

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

From the remarks section of IsolatedStorageSettings.Save Method page:

Data written to the IsolatedStorageSettings object is saved when the application that uses the class is closed. This can occur when the user closes the Web browser, refreshes a page, or browses away from the page. If you want your application to write to isolated storage immediately, you can call the Save method in application code.

So, I can never call the Save method and every setting will be in safety. I'm just curious in what usecases should I use the Save method?

You have to call IsolatedStorageSettings.Save yourself. 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. 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.

Here is the documentation for the IsolatedStorageSettings.Save method dated February 14, 2014:

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. The data that you store in the IsolatedStorageSettings object is saved automatically.

My dev experience also proves that - the settings are saved automatically without the need to call the Save method explicitly. But note that it happens only when you close the whole app, excatly as it is stated in MSDN:

Data written to the IsolatedStorageSettings object is saved when the application that uses the class is closed. If you want your application to write to isolated storage immediately, you can call the Save method in application code.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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