title: Poor performance when modifying appSettings
body: <p>I have an application in which I create a TreeView from the values of a database and display it with checkboxes.
  Now I want to write the selected values into the appSettings. I tried to do this with this code.
  But the performance is so bad, that this probably can't be the right way.
  How can I solve it better?</p>
  
  <pre><code>public static void SearchAndSaveSelectedNodes(TreeNodeCollection nodes)
  {
      foreach (TreeNode n in nodes)
      {
          DeleteSetting(n.Name);
  
          if (n.Checked)
          {
              UpdateSetting(n.Name, n.Name + "@" + n.FullPath);
          }
          SearchAndSaveSelectedNodes(n.Nodes);
      }
  }
  
  public static void DeleteSetting(string key)
  {
      System.Configuration.Configuration config = `ConfigurationManager.OpenExeConfiguration(ConfigurationUserLevel.None);`
      config.AppSettings.Settings.Remove(key);
      config.Save(ConfigurationSaveMode.Modified);
      ConfigurationManager.RefreshSection("appSettings");
      ConfigurationManager.RefreshSection(config.AppSettings.SectionInformation.Name);
  }
  
  public static void UpdateSetting(string key, string value)
  {
      System.Configuration.Configuration config = ConfigurationManager.OpenExeConfiguration(ConfigurationUserLevel.None);
      config.AppSettings.Settings.Remove(key);
      config.AppSettings.Settings.Add(key, value);
      config.Save(ConfigurationSaveMode.Modified);
      ConfigurationManager.RefreshSection("appSettings");
      ConfigurationManager.RefreshSection(config.AppSettings.SectionInformation.Name);
  }
  </code></pre>