How does LocalSettings work?

风流意气都作罢 提交于 2019-12-13 21:30:29

问题


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?

And the main purpose of the question:

  • 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?

回答1:


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.

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



来源:https://stackoverflow.com/questions/24483381/how-does-localsettings-work

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!