C#一个窗体程序,读取配置文件中一个数据显示在textbox中可修改,修改后点击按钮保存即更新配置文件。
这些都实现了。
可是程序还是用的改之前的数据。就是一个定时执行的事件,时间写在配置文件里,页面可以修改这个时间。初始化是5分钟执行一次,然后改成10分钟,修改配置文件成功后,程序依然5分钟一次,但是重启这个程序后就变成10分钟了。什么 this.Refresh();还有重新加载都试过了没什么用 , 所以求助各位大神 ,求指教!

解决方案 »

  1.   

     如果要得到更改后的即时数据,建议自己加一个xml文件,专门做应用程序的配置设置。不要用App.config了 
      

  2.   

    你在每次读取的时候 前面加一句这个 记得添加 System.Configuration 这个引用 他不是 System 下的那个 配置管理器System.Configuration.ConfigurationManager.RefreshSection(string sectionName);
      

  3.   

    string configFileName = Application.ExecutablePath + ".config"; 
    System.Xml.XmlDocument doc = new System.Xml.XmlDocument(); 
    doc.Load(configFileName); 
    string configString = @"configuration/applicationSettings/SetConfig.Properties.Settings/setting[@name='appSetting1']/value"; 
    System.Xml.XmlNode configNode = doc.SelectSingleNode(configString); 
    if (configNode != null) 

       configNode.InnerText = this.TextBox1.Text; 
       doc.Save(configFileName); 
       Properties.Settings.Default.Reload();  

      

  4.   


    全局:
    Thread mythread1;
    System.Threading.Timer timer;
    string configValue="";
    Form_Load事件下
     private void MainForm_Load(object sender, EventArgs e)
    {
         mythread1 = new Thread(new ThreadStart(RunMyThread1));
         mythread1.IsBackground = true;
         mythread1.Start();
    } //线程1   获取json数据
    private void RunMyThread1()
    {
         int times = Convert.ToInt32(getConn("time"));
         TimerCallback timerDelagete = new TimerCallback(getjson);
         timer = new System.Threading.Timer(timerDelagete, null, times, times);
     }private void getjson()
    {
         MessageBox.Show("获取");
    }//获取读取config节点
    public string getConn(string config)
    {
         configValue = System.Configuration.ConfigurationSettings.AppSettings["" + config+""];
         return configValue;
    }
      

  5.   


    有啊,有引用的。 我这个定时用的是Thread命名空间下的,不是timer