变化的AppSettings需要重新启动我的应用我如何才能避免? [英] Change in AppSettings needs restart my Application how can I avoid?

查看:190
本文介绍了变化的AppSettings需要重新启动我的应用我如何才能避免?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

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

和我使用的app.config我的应用程序设置。

但变化的AppSettings不反映运行时,它需要应用程序重新启动。

我怎样才能避免它。

下面是我的code片断我用来读取和写入的应用程序设置。

我在读的设置像这样

 字符串临时= ConfigurationManager.AppSettings.Get(密钥);
 

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

  node.Attributes [值]值=价值;
xmlDoc.Save(AppDomain.CurrentDomain.SetupInformation.ConfigurationFile);
 

解决方案

您可以尝试调用

  ConfigurationManager.RefreshSection(的appSettings) 

刷新从磁盘上的文件appSettings部分。一旦它们被刷新,你应该能够读取新的值。

我刚刚测试过这一点,它确实工作。

I'm using C# .NET 2.0 Windows Application.

and I'm using app.config for my Application Settings.

but change in AppSettings doesn't reflected runtime, it Needs Application to be restarted.

How can I avoid it.

Here is my code snippet I used to read and write the Application Settings.

I'm reading the Setting like this

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

I'm updating the value like this where node is the current configuration/appSettings Node

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

解决方案

You could try calling

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.

I've just tested this and it does indeed work.

这篇关于变化的AppSettings需要重新启动我的应用我如何才能避免?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆