为什么app.config要重启后才能生效?

gdfg34324 2009-12-15 06:52:27

private void callWeatherService()
{
try
{
string weatherCityName = "";
weatherCityName = ConfigurationManager.ConnectionStrings["chengshi"].ToString();
关于.cn.com.webxml.www.WeatherWebService weatherWS = new WeatherWebService();
array = weatherWS.getWeatherbyCityName(weatherCityName);

}
catch
{
MessageBox.Show("天气错误!");


///设置天气预报的城市
///
        private void button8_Click(object sender, EventArgs e)
{

if(textBox3.Text=="")
{
MessageBox.Show("请输入城市名字!");
}
else
{
string Xvalue=textBox3.Text;
UpdateConfig(Xvalue);
callWeatherService();
string str1="",str2="";
chosePictureBox(str1, str2) ;
showWeather();
}

}


///更新天气预报的城市
        private   void   UpdateConfig(string   Xvalue)
{
XmlDocument doc = new XmlDocument();
doc.Load(Application.ExecutablePath+".config");
XmlNode node = doc.SelectSingleNode(@"//add[@name='chengshi']");
XmlElement ele = (XmlElement)node;
ele.SetAttribute("connectionString", Xvalue);
doc.Save(Application.ExecutablePath+".config");
}


为什么设置城市之后,需要重新启动程序才能生效呢,很奇怪
...全文
196 7 打赏 收藏 转发到动态 举报
写回复
用AI写文章
7 条回复
切换为时间正序
请发表友善的回复…
发表回复
gdfg34324 2009-12-17
  • 打赏
  • 举报
回复
那我如何调用xml这个文件呢
zhujiazhi 2009-12-15
  • 打赏
  • 举报
回复
把要配置的城市内容放入一个xml中的,如
<xml>
<root>
<city>suzhou</city>
</root>
</xml>

然后在调用的时间就读这个xml的,随时都能生效的
gdfg34324 2009-12-15
  • 打赏
  • 举报
回复
<add name="chengshi" connectionString="" />这个就是我的配置文件,但是每次都要重启才能生效,很麻烦
gdfg34324 2009-12-15
  • 打赏
  • 举报
回复
还是不明白啊
wuyq11 2009-12-15
  • 打赏
  • 举报
回复
参数配置在XML中
gdfg34324 2009-12-15
  • 打赏
  • 举报
回复
怎么做?
wuyq11 2009-12-15
  • 打赏
  • 举报
回复
用户更改设置后,从配置文件中读取新的信息
使用XML配置

110,533

社区成员

发帖
与我相关
我的任务
社区描述
.NET技术 C#
社区管理员
  • C#
  • Web++
  • by_封爱
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告

让您成为最强悍的C#开发者

试试用AI创作助手写篇文章吧