1
应用程序启动后,如果我更改app.config中的某个值,它是否反映在通过其访问appconfig属性的缓存对象中。Dot net 3.5:appconfig是否在运行时在缓存中动态更新?
string currentValue = ConfigurationSettings.AppSettings[currentKey];
如果不是那么可行的办法是什么?
应用程序启动后,如果我更改app.config中的某个值,它是否反映在通过其访问appconfig属性的缓存对象中。Dot net 3.5:appconfig是否在运行时在缓存中动态更新?
string currentValue = ConfigurationSettings.AppSettings[currentKey];
如果不是那么可行的办法是什么?
不,它不会自动更新。要强制刷新,您可以使用RefreshSection方法:
Console.WriteLine(ConfigurationManager.AppSettings["test"]);
Console.WriteLine("Now modify app.config value");
Console.ReadLine();
ConfigurationManager.RefreshSection("appSettings");
Console.WriteLine(ConfigurationManager.AppSettings["test"]);