0

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?
Romasz
  • 29,662
  • 13
  • 79
  • 154

1 Answers1

3

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.

Sean McKenna
  • 3,706
  • 19
  • 19
  • So as I understand, there is no need to gurad settings with Mutex when using them in multiple processes/threads, because the OS it performing all actions synchronously. Does this also mean that read and write operations are stacked in the same queue (one is performed when the other competes)? – Romasz Jul 01 '14 at 19:14
  • Correct. You do not need to maintain your own mutex - the platform will manage synchronization for you. You should not make any assumptions about the ordering of the writes, however. – Sean McKenna Jul 01 '14 at 21:12