AppSettings 的更改需要重新启动我的应用程序,我该如何避免?

2024-01-29

我正在使用 C# .NET 2.0 Windows 应用程序。

我正在使用 app.config 作为我的应用程序设置。

但 AppSettings 中的更改不会反映运行时,它需要重新启动应用程序。

我怎样才能避免呢。

这是我用来读取和写入应用程序设置的代码片段。

我正在这样阅读设置

string temp = ConfigurationManager.AppSettings.Get(key);

我正在更新这样的值,其中节点是当前配置/appSettings 节点

node.Attributes["value"].Value = value;
xmlDoc.Save(AppDomain.CurrentDomain.SetupInformation.ConfigurationFile);

你可以尝试打电话

ConfigurationManager.RefreshSection("appSettings")
to refresh the AppSettings section of the file from disk. Once they have been refreshed, you should be able to read the new values.

我刚刚测试过这个,它确实有效。

本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)

AppSettings 的更改需要重新启动我的应用程序,我该如何避免? 的相关文章

随机推荐