Search code examples
c#.netapplication-settings

How to change application settings (Settings) while app is open?


I've written a class that should allow me to easily read and write values in app settings:

public static class SettingsManager
    {
        public static string ComplexValidationsString
        {
            get { return (string)Properties.Settings.Default["ComplexValidations"]; }
            set
            {
                Properties.Settings.Default["ComplexValidations"] = value;
                Properties.Settings.Default.Save();
            }
        }

the problem is the value isn't really saved, I mean it is not changed when I exit the application and run it again. What can I do to ensure that the saved value persists between closing and opening again?


Solution

  • You should check

    Properties.Settings.Default.Properties["ComplexValidations"].IsReadOnly
    

    It is probably true, this is what Roland means with "Application Scope". Save will fail silently. Take a look at Project|Properties|Settings, 3rd column.