I have been working with Console applications before and using App.config. Now I am trying to create WPF tool and went with App.config as well. However while testings I have noticed strange behavior and later discovered that after writing to App.config application should be closed and opened again so that changes in App.config will take in place.
I have a method for updating values in App.config:
private static void UpdateSetting(string key, string value)
{
Configuration configuration = ConfigurationManager.OpenExeConfiguration(ConfigurationUserLevel.None);
configuration.AppSettings.Settings[key].Value = value;
configuration.Save();
ConfigurationManager.RefreshSection("appSettings");
}
And button:
private void Button_Click_1(object sender, RoutedEventArgs e)
{
UpdateSetting("MinutesExecution", MinutesToWait.Text);
MessageBox.Show("Your changes has been saved!");
}
Is there any other way so that my changes to settings will be taken in consideration without closing an application? I know I can create separate file and read from there but is there any built in function that can be used in Visual Studio like App.config?