从SuperSocket的App.config中读取配置,并修改保存,再重启服务
string XmlPath = System.Windows.Forms.Application.ExecutablePath + ".config"; XmlDocument xDoc = new XmlDocument(); xDoc.Load(XmlPath); XmlNode Node_superSocket= xDoc.SelectSingleNode("//superSocket"); if (Node_superSocket == null) { return; } XmlNode Node_servers= Node_superSocket.SelectSingleNode("//servers"); if (Node_servers == null) { return; } XmlNode Node_server = Node_servers.FirstChild; if (Node_server == null) { return; } #region 参数合法性检查 #endregion XmlAttribute att; att = Node_server.Attributes["ip"]; att.Value = this.tb_ip.Text; att = Node_server.Attributes["port"]; att.Value = this.tb_port.Text; att = Node_server.Attributes["idleSessionTimeOut"]; att.Value = this.tb_idleSessionTimeOut.Text; att = Node_server.Attributes["receiveBufferSize"]; att.Value = this.tb_receiveBufferSize.Text; att = Node_server.Attributes["maxConnectionNumber"]; att.Value = this.tb_maxConnectionNumber.Text; xDoc.Save(XmlPath); Application.ExitThread(); Application.Exit(); Application.Restart(); Process.GetCurrentProcess().Kill();