刷新/清除 app.config 的缓存

发布于 2024-09-08 18:36:14 字数 686 浏览 2 评论 0原文

我试图在 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 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

枉心 2024-09-15 18:36:14

您是否检查了 Documents and Settings/youruser(Windows7 用户)中的配置?

Did you check config in Documents and Settings/youruser (Users for Windows7)?

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文