2
我试图从app.config运行时获取更新值。我尝试了几种方法,但仍使用旧值。我怎样才能正确刷新它?我试过这些,但它不起作用:刷新/清除app.config的缓存
MessageBox.Show(Properties.Settings.Default.MyValue);
Properties.Settings.Default.Reload();
Properties.Settings.Default.Upgrade();
Properties.Settings.Default.Reset();
ConfigurationManager.RefreshSection("applicationSettings");
ConfigurationManager.RefreshSection("/applicationSettings/");
ConfigurationManager.RefreshSection("/configuration/applicationSettings");
MessageBox.Show(Properties.Settings.Default.MyValue);
MyValue的值是“第一个值”。
这首先显示“第一个值”。当消息框仍然打开时,我手动将其从my.exe.config更改为“第二个值”,第二个消息框仍显示“第一个值”。我没有运行解决方案,我直接从bin文件夹运行exe文件,所以它不是vshost问题。
我该怎么办?
请参阅http://stackoverflow.com/questions/272097/net-dynamically-refresh-app-config – stuartd 2012-09-23 13:57:38