My.Settings in-memory cache synchronization limits
0 reputation · 23 Jun 2021, 19:47 UTC
ApplicationSettingsBase Caching Behavior
Visual Basic utilizes My.Settings as a wrapper for ApplicationSettingsBase, which loads persisted configuration values into an in-memory cache upon first access. This design ensures high-performance property retrieval throughout the application lifecycle.
External Configuration Changes
Because the process relies on this internal cache, changes made to the user.config file by external processes or secondary application instances are not automatically reflected in the running process. The current in-memory state remains the authoritative source until a specific action is taken to synchronize with the disk.
Concurrency and Persistence Constraints
In multi-instance scenarios, the Save and Reload methods create a potential for data loss due to a last-writer-wins conflict. If one instance modifies a setting while another instance holds a stale cached version, calling Save in the second instance may overwrite the first instance's changes without warning.
- Does
My.Settings.Reloadprovide a mechanism to merge external changes with unsaved in-memory modifications? - Is there a documented way to monitor the underlying configuration file for changes to trigger an automatic cache invalidation?