c# - Why is isolated storage not persisting in my WP7 application? -
i using isolatedstoragesettings.applicationsettings application. code associated isolated storage occurs in application_launching, application_activated, application_closing, , application_deactivated methods follows:
public isolatedstoragesettings settings = isolatedstoragesettings.applicationsettings; private void application_launching(object sender, launchingeventargs e) { if (settings.contains("myobjlist")) { app.objlist = (observablecollection<myobj>)settings["myobjlist"]; } else { settings.add("myobjlist", app.objlist); } } private void application_activated(object sender, activatedeventargs e) { if (settings.contains("myobjlist")) { app.objlist = (observablecollection<myobj>)settings["myobjlist"]; } else { settings.add("myobjlist", app.objlist); } } private void application_deactivated(object sender, deactivatedeventargs e) { settings["myobjlist"] = app.objlist; settings.save(); } private void application_closing(object sender, closingeventargs e) { settings["myobjlist"] = app.objlist; settings.save(); }
all of occurring in app.xaml.cs file created default every new application.
i have tried exiting application using button using windows button. leaving emulator running, tried reopening application using button, , navigating application list , opening.
the issue having on load or activation settings.contains["myobjlist"] returning false , proceeding add key settings on again.
does see why settings key (and value) not persisting?
i see issues:
the isolatedstoragesettings doc explicitly says not call save() because it's not thread safe (scroll down platform notes wp) , may raise exception (and cause settings not saved).
it seems not case here, using string "myobjlist" around pretty dangerous it's easy mispell. put inside constant , rule out typing error
in experience isolatedstoragesettings not robust on current wp7 version. better create class , serialize isolatedstorage file. anyways going on app have more things save , have cleaner code way.
Comments
Post a Comment