C#按钮更新(刷新)xml值

时间:2014-05-04 08:35:42

标签: c# xml winforms visual-studio xpath

我在Visual Studio中处理小型天气应用程序,除了一个功能外,一切正常。  我无法使用我的更新按钮(btnUpdate_Click)。它应该做的是实时刷新或更新xml-file(url)的温度值!

我已经尝试将显示温度的所有标签重置为string.empty然后使用XMLDocument重新加载(刷新)该值,但它不起作用:/ 需要帮忙!

2 个答案:

答案 0 :(得分:0)

而不是使用

serverDoc.Load(

serverDoc.LoadXML()方法

答案 1 :(得分:0)

可能我错过了一些东西,但我会尝试在ThreadPool中使用TemperaturePresenter类的单独方法完成工作。
我会从构造函数中调用此方法来获取实际行为,但是,现在我可以在按钮内再次调用该方法单击

  public TemperaturePresenter()
  {
     _view = new MainView(this);
     serverDoc = new XmlDocument();
     responseDoc = new XmlDocument();
     LoadTemperatures();
  }
  public void LoadTemperatures()
  {
        ThreadPool.QueueUserWorkItem(
        delegate
        {
            .. a lot of things to check here ...
        }
  }

  ,,,,,


  public void btnUpdate_Click(object sender, EventArgs e)
  {            
     _parent.LoadTemperatures();
  }