为什么是孤立的存储不是我的WP7应用程序坚持? [英] Why is isolated storage not persisting in my WP7 application?

查看:150
本文介绍了为什么是孤立的存储不是我的WP7应用程序坚持?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我使用IsolatedStorageSettings.ApplicationSettings我的应用程序。与独立存储相关联的所有代码出现在我的Application_Launching,Application_Activated,Application_Closing和Application_Deactivated方法如下:

I am using IsolatedStorageSettings.ApplicationSettings for my application. All code associated with Isolated storage occurs in my Application_Launching, Application_Activated, Application_Closing, and Application_Deactivated methods as 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();
}



所有这一切都在创建的App.xaml.cs文件中发生的默认情况下,每一个新的应用程序。

All of this is occurring in the App.xaml.cs file that is created by default with every new application.

我曾尝试使用退出后退按钮以及通过使用Windows键的应用程序。离开模拟器中运行,我尝试使用后退按钮重新打开应用程序,并导航到应用程序列表开放。

I have tried exiting the application using the back button as well as by using the windows button. Leaving the emulator running, I tried reopening the application using the back button, and navigating to the application list and opening.

我遇到的问题是,在负载或激活在settings.Contains [myObjList]被返回false,并着手一遍添加关键设置。

The issue I am having is that on load or activation the settings.Contains["myObjList"] is returning false and proceeding to add the key to settings all over again.

有谁知道为什么我的设置键(和值) ?不是持久的。

Does anyone see why my settings key (and value) is not persisting?

推荐答案

我看到一些问题:


  1. IsolatedStorageSettings DOC 明确说的的调用保存(),因为它不是线程安全的(向下滚动,为WP平台票据),并可能引发异常(并导致您的设置不要保存)。

  1. The IsolatedStorageSettings doc explicitly says not to call Save() because it's not thread safe (scroll down to the platform notes for WP) and may raise an exception (and cause your settings not to be saved).

这似乎不是这里出现这种情况,但使用字符串myObjList一切围绕是相当危险的,因为它很容易mispell。我会把它里面的一个常量,排除任何输入错误

It seems not to be the case here, but using the string "myObjList" all around is pretty dangerous as it's easy to mispell. I would put it inside a constant and rule out any typing error

在我的经验 IsolatedStorageSettings是不能在当前版本的WP7非常强大。你最好创建一个类,并将其序列化为一个IsolatedStorage文件。反正事情与你的应用程序,你可能有更多的事情要保存,你将有更干净的代码的方式。

In my experience IsolatedStorageSettings is not very robust on the current WP7 version. You better create a class and serialize it into an IsolatedStorage file. Anyways going on with your app you will probably have more things to save and you will have cleaner code that way.

这篇关于为什么是孤立的存储不是我的WP7应用程序坚持?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆