已有56人关注
在线升级模块问题 《C#开发典型模块大全(修订版)》老师还要请教您,拜托了!~
发表在C#图书答疑 2010-10-20
是否精华
版块置顶:
就是XML文件在读取是调用了operateclass类中的以下这个方法。
public Hashtable SelectXML(string strPath) 
{
Hashtable HTable = new Hashtable();
XmlDocument doc = new XmlDocument();
doc.Load(strPath);

//获取NewDataSet节点的所有子节点
XmlNodeList xnl = doc.SelectSingleNode("UpdCfg").ChildNodes;
string strVersion = "";
string strInfo = "";
foreach (XmlNode xn in xnl)//遍历UpdCfg节点下的所有子节点
{
XmlElement xe = (XmlElement)xn; //将子节点类型转换为XmlElement类型
if (xe.Name == "Upgrade") //判断节点名为Upgrade
{
XmlNodeList xnlChild = xe.ChildNodes; //继续获取xe子节点的所有子节点
foreach (XmlNode xnChild in xnlChild) //遍历Upgrade节点下的所有子节点
{
XmlElement xeChild = (XmlElement)xnChild; //转换类型
if (xeChild.Name == "Version")
{
strVersion = xeChild.InnerText;
}
if (xeChild.Name == "UpdInfo")
{
strInfo = xeChild.InnerText;
}
}
HTable.Add(strVersion, strInfo);
}
}
doc.Save(strPath);

return HTable;
}

读取xml文件时,用的是XMLDocument的Load方法读取的,如何释放呢,没有找到相关的方法。
在客户端的主窗体加载时,调用了ControlUpdate() 方法。
private void ControlUpdate() 
{

HNativeTable = operateclass.SelectXML(strOldXmlName);
HServerTable = operateclass.SelectXML(strNewXmlName);
IDictionaryEnumerator IDEnumeratorNative = HNativeTable.GetEnumerator();
IDictionaryEnumerator IDEnumeratorServer = HServerTable.GetEnumerator();
string str = "";
while (IDEnumeratorNative.MoveNext())
{
if (str == "")
str = IDEnumeratorNative.Key.ToString();
else
str += "\n" + IDEnumeratorNative.Key.ToString(); 
}
//获取本地机器的最新版本
if (str.IndexOf("\n") != -1)
strOldVersion = str.Substring(str.LastIndexOf("\n") + 1, str.Length - str.LastIndexOf("\n") - 1);
else
strOldVersion = str;
//使用本地机器上的最新版本与服务器上的新版本进行比较
while (IDEnumeratorServer.MoveNext())
{
if (string.Compare(strOldVersion, IDEnumeratorServer.Key.ToString()) < 0)
list.Add(IDEnumeratorServer.Key.ToString());
}
if (list.Count > 0)
{
ClientUpdateForm clientUpdateForm = new ClientUpdateForm();
clientUpdateForm.Show();
}
else
{
MessageBox.Show("当前版本已经是最新版本,不需要升级!","提示",MessageBoxButtons.OK,MessageBoxIcon.Information);
}
}

其中的 HNativeTable = operateclass.SelectXML(strOldXmlName);
HServerTable = operateclass.SelectXML(strNewXmlName);
就是导致问题的所在,由于第一次调用SelectXML时,xml文件没有关闭,导致第二次无法读取xml文件,这个问题,我没有找到解决方法,您给我一点代码提示好吗?
而我对进程那块不太懂,您能否附上相应的代码或者释放XML文件的解决办法。
多谢老师了,我都纠结了两天了,拜托老师了! 
分享到:
精彩评论 3
小科_mrkj
学分:43 LV2
2010-10-20
沙发
读者朋友:
您好,杀死相关进程的代码如下:
Process Pro=new Process();
foreach(Process p in Process.GetProcessesByName("进程名"))
{
if(!p.CloseMainWindow())
{
p.Kill();
}
}
用这种方法杀掉XML进程,然后再运行程序。
mutou
学分:0 LV1
TA的每日心情
开心
2022-07-25 10:41:35
2010-10-21
板凳
[FIELDSET][LEGEND]引自:1楼[/LEGEND]
读者朋友:
您好,杀死相关进程的代码如下:
Process Pro=new Process();
foreach(Process p in Process.GetProcessesByName("进程名"))
{
if(!p.CloseMainWindow())
{
p.Kill();
}
}
用这种方法杀掉XML进程,然后再运行程序。
[/FIELDSET]

回复:
太感谢老师了,这个问题终于解决了!看来我要好好学习进程和线程这块,挺重要的
  
mutou
学分:0 LV1
TA的每日心情
开心
2022-07-25 10:41:35
2010-10-21
地板
[FIELDSET][LEGEND]引自:1楼[/LEGEND]
读者朋友:
您好,杀死相关进程的代码如下:
Process Pro=new Process();
foreach(Process p in Process.GetProcessesByName("进程名"))
{
if(!p.CloseMainWindow())
{
p.Kill();
}
}
用这种方法杀掉XML进程,然后再运行程序。
[/FIELDSET]

回复:
太感谢老师了,这个问题终于解决了!看来我要好好学习进程和线程这块,挺重要的
  
首页上一页 1 下一页尾页 3 条记录 1/1页
手机同步功能介绍
友情提示:以下图书配套资源能够实现手机同步功能
明日微信公众号
明日之星 明日之星编程特训营
客服热线(每日9:00-17:00)
400 675 1066
mingrisoft@mingrisoft.com
吉林省明日科技有限公司Copyright ©2007-2022,mingrisoft.com, All Rights Reserved长春市北湖科技开发区盛北大街3333号长春北湖科技园项目一期A10号楼四、五层
吉ICP备10002740号-2吉公网安备22010202000132经营性网站备案信息 营业执照