问题
If I create a user level application setting and bind it to a text box on a form, then type something in the textbox, the value is automatically saved and when the application is launched again the value appears in the textbox. This doesn't happen when I scope the setting as application.
Why are application scoped settings not saved automatically like user scoped settings are?
If this is by design, how can I manually save these settings and load them at runtime?
回答1:
In short, application scoped settings can't be changed at runtime while user scoped settings are designed be read/written at runtime. There are a number of alternatives to using application scoped settings:
- Use user scoped settings
- This post recommends looking into the ConfigurationManager class.
- If you don't like user scoped settings because they are not written to the application directory you can implementing your own SettingsProvider and have them written where ever you'd like
This post has some recommendations on how to best manage settings. Finally, here is Microsoft's documentation on the settings architecture if you're interested in extending theirs or rolling your own.
来源:https://stackoverflow.com/questions/10145955/application-settings-scope-user-vs-application