刷新/清除 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 问题。
我应该怎么办?
I'm trying to get update values from app.config while it's running. I tried several methods but it still uses old values. How can I get correctly refresh it? I tried these but it didn't work:
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);
The value of MyValue is "first value".
This first displays "first value". While the message box is still open I manually change it from my.exe.config to "second value" and the second message box still displays "first value". I'm not running the solution, I'm directly running the exe from bin folder so it's not vshost problem.
What should I do?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
您是否检查了 Documents and Settings/youruser(Windows7 用户)中的配置?
Did you check config in Documents and Settings/youruser (Users for Windows7)?