开发者

windows phone 7 + IsolatedStorageSettings + Add and Save function

In Windows Phone 7 -> IsolatedStorageSettings class we have two functions Add() and Save(). According to me both are doing the same thing meanings saving a key value pair in Isolated Storage. My question what is the difference between these two functions.

To test this what is did was in App.xaml.cs in Application_Deactivated event and Application_Closing event I added one key value pair in IsolatedStorageSettings without calling the save function.

On Application_Launched and Application_Act开发者_开发百科ivated event I am retrieving same key value pair and I am getting same value for the key which I had added above.

So, without actually calling Save function of IsolatedStorageSettings I am able to retrieve the values.


.Save() actually persists the isolated storage settings instance (such as ApplicationSettings) to the media (e.g. phone storage).

This is automatically done when your application is tombestoned (_Deactivated) or closed (_Closed). That is why you get same value without even calling save.

.Add() method just adds a new entry to your dictionary of settings. This change may be missed if your settings is not saved (usually when app is exited unexpectedly).

From MSDN:

"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."

Hope this answers your question

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜