本地设置如何工作? [英] How does LocalSettings work?

查看:15
本文介绍了本地设置如何工作?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在为一个问题苦苦挣扎 - 事实上 LocalSettings 工作.这是一个 ApplicationDataContainer 类,但这是某种文件吗?可能是的,但是什么时候保存?

i'm struggling myself with a question - how does in fact LocalSettings work. It's an ApplicationDataContainer class, but is this some kind of a file? Probably yes, but when it's saved?

例如我们可以这样保存一些数据:

For example we can save some data like this:

localSettings.Values["exampleSetting"] = "Hello Windows";

但是它是在我们添加/更改值后立即保存到文件中还是保存在内存中的某个位置并在应用程序暂停/终止时保存?

but is it saved to file just after we add/change the Value or it's held somewhere in the memory and saved when App is being Suspended/Terminated?

以及问题的主要目的:

  • 当从并发进程/线程访问 LocalSettings 时,我是否必须使用 Mutex 来保护上述代码行?
  • 同时保存 LocalSettings 时是否有可能出现异常?
  • Do I've to guard the above line of code for example with a Mutex when accessing LocalSettings from concurrent processes/threads?
  • is there a chance we can get an exception when saving LocalSettings at the same time?

推荐答案

LocalSettings(和 RoamingSettings)提供了一个在概念上等同于 Windows 注册表的访问模型.写入操作是同步的、原子的,并且实现最后写入者获胜语义.对设置所做的任何更改都会立即可供其他线程使用.

LocalSettings (and RoamingSettings) provide an access model that is conceptually equivalent to the Windows registry. Write operations are synchronous, atomic, and implement last writer wins semantics. Any changes made to settings are immediately available to other threads.

注意:如果您需要创建包含多个键/值对的原子设置,您应该使用 ApplicationDataCompositeValue 类.

Note: If you need to create an atomic setting that contains multiple key/value pairs, you should use the ApplicationDataCompositeValue class.

这篇关于本地设置如何工作?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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