isolatedStorageSettings.ApplicationSettings 不被存储

发布于 2024-12-11 08:39:58 字数 639 浏览 0 评论 0原文

我试图保留我访问应用程序的最后日期,环顾四周后,我在 App.xaml.cs 中想到了这个 init:

appSettings = IsolatedStorageSettings.ApplicationSettings;
             try
            {
                Debug.WriteLine("INIT LAST MODIFIED " + (string)appSettings["lastModifiedDate"]);
            }
            catch (KeyNotFoundException)
            {
                appSettings.Add("lastModifiedDate","");
            }

逻辑是,如果尝试显示尚未添加的值(第一次运行),我得到一个异常 KeyNotFoundException。这一切都很好..问题是当我重新启动应用程序时,代码仍然调用异常(就好像未设置变量一样)。如果有人可以回答,我有一些问题:

1)应用程序设置在应用程序关闭后是否仍然存在?(我理解他们会这样做)

2)模拟器是否存储这些值?

如果这些问题中的任何一个都没有问题,那么您是否找出问题所在?

i am trying to retaing the last date that i have visited my app, and after looking around i came up with this init in the App.xaml.cs:

appSettings = IsolatedStorageSettings.ApplicationSettings;
             try
            {
                Debug.WriteLine("INIT LAST MODIFIED " + (string)appSettings["lastModifiedDate"]);
            }
            catch (KeyNotFoundException)
            {
                appSettings.Add("lastModifiedDate","");
            }

The logic is that if try to display a value that hasn't been added (the first run), i get an exception KeyNotFoundException. This is all good.. The problem is when i restart my application, the code still calls the exception(as if the variable isn't set). A have some questions if anyone could answer:

1) Does the app setting survive after an app close?(i understood they do)

2) Does the simulator store this values or not?

If any of these issues are ok, do you figure out what is the problem?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

就此别过 2024-12-18 08:39:58
appSettings.Save();

这里有你需要的线路!

哦 - 是的,模拟器将存储设置,直到您:

  1. 重建项目
  2. 关闭模拟器并重新加载它。

每次重新加载模拟器时,它都会重新启动,就像以前从未运行过一样。当您重建项目(不仅仅是构建,而是单击“构建|重建”)时,它会将其从模拟器中删除。它会在实际设备上执行相同的操作。因此,任何时候您想要拥有它,就像您第一次运行应用程序一样,重建,无论是在手机上还是在模拟器上。

appSettings.Save();

There's the line you need!

Oh - and yes, the emulator will store the settings, UNTIL you either:

  1. Rebuild the project
  2. Close the emulator and reload it.

Every time you reload the emulator, it starts fresh, as if it had never run before. And when you rebuild a project (not just build, but click Build|Rebuild), it will remove it from the emulator. It will do the same on an actual device. So anytime you want to have it so that it is like the first time you run the app, rebuild, whether it is on phone or emulator.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文