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