0
votes

I'm using IsolatedStorageSettings on WP7 to store an objects list:

List<T>

I need to search an item inside my list and to update some properties of the searched item.

I'm using this code:

List<Article> listArt = null;
IsolatedStorageSettings.ApplicationSettings.TryGetValue("ArticleListStorage", out listArt);

var queryList = (from anItem in listArt where (anItem.Id == _id) select anItem).ToList<Article>();

a = queryList[0] as Article;

//mark Article as read
a.Readed = true;

When I continuously navigate the various page inside the app, I can see the property Readed correctly evalued.

But, when I click on WP7 Start button and reopen my app (without close emulator) I see the property not correctly evalued.

Need I to update my object inside list and so inside Isolated Storage?

Not updated by reference?

I tried also this, ant it doesn't work:

listArt[0].Readed = true;
listArt[0].Favorite = true;

IsolatedStorageSettings.ApplicationSettings["ArticleListStorage"] = listArt;

IsolatedStorageSettings.ApplicationSettings.Save();

What is wrong?

Thank you so much!

2

2 Answers

2
votes

You can either explicitly call Save() on the settings or wait for the app to close normally and then they will be saved automatically.

As a general rule I'd suggest always explicitly saving settings once you change them. (Unless you have a very good reason not to.)

What's happening in your situation is that you are pressing the start button which causes your app to tombstone. When you launch a new instance of the app the tombstoned version is destroyed without all the code which normally runs on application close (including auto-saving settings) being executed.

Here's and example of using Save:

var settings = IsolatedStorageSettings.ApplicationSettings;

if (settings.Contains("some-key"))
{
    settings.Remove("some-key");
}

settings.Add("some-key", "my-new-value");
settings.Save();
1
votes

Yes, you've got to save your list again. Think of isolated storage as a file system - you wouldn't expect to be able to load an XDocument from disk, make changes in memory and automatically see those changes reflected on disk, would you? Well, it's the same with isolated storage.