Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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?

like image 396
ie. Avatar asked Jan 15 '23 03:01

ie.


2 Answers

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.

like image 123
tombrtls Avatar answered Feb 04 '23 15:02

tombrtls


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.

like image 41
TecMan Avatar answered Feb 04 '23 17:02

TecMan