我正在VB.net中开发多线程客户端-服务器应用程序,其中多个客户端连接到一个服务器,服务器端也有打开XML文件并写入一些数据的进程。但 1 小时后,我收到以下错误:
“文件被另一个进程使用。”
对于上述问题,您有什么建议吗?请检查我下面的代码以阅读 XML
Public Function ISRecordExitsinXML(ByVal pFilepath As String, ByVal pClientIP As String, ByVal pMacAddress As String)
Dim xmlDoc As XmlDocument = Nothing
Dim xmlPupilNode As XmlNode = Nothing
Dim xmlAgeNode As XmlNode = Nothing
Try
Dim FileName As String = pFilepath
ISRecordExitsinXML = Nothing
xmlDoc = New XmlDocument
xmlDoc.Load(FileName)
xmlPupilNode = xmlDoc.SelectSingleNode("//RFIDReader[HostIPAddress = '" & pClientIP.Trim & "' and MacAddress = '" & pMacAddress & "' and Status=1] ")
If Not xmlPupilNode Is Nothing Then
xmlAgeNode = xmlPupilNode.SelectSingleNode("RegDateTime")
If Not xmlAgeNode Is Nothing Then
xmlAgeNode.InnerText = DateTime.Now.ToString()
xmlDoc.Save(FileName)
ISRecordExitsinXML = True
End If
Else
ISRecordExitsinXML = False
End If
xmlDoc = Nothing
xmlPupilNode = Nothing
xmlAgeNode = Nothing
Catch ex As Exception
xmlDoc = Nothing
xmlPupilNode = Nothing
xmlAgeNode = Nothing
ISRecordExitsinXML = False
ErrorLog.WriteToErrorLog(ex.Message.ToString(), "HSRV-A9", "ErrorLog.Log")
Finally
xmlDoc = Nothing
xmlPupilNode = Nothing
xmlAgeNode = Nothing
End Try
Return ISRecordExitsinXML
End Function
提前致谢