我有一个MVC应用程序,我用它来处理XML文件的列表文件夹,我有以下代码:
Function Backlog598()
'Dim dir As New DirectoryInfo(Server.MapPath("~/598/"))
Dim fileArray As FileInfo() = dir.GetFiles()
Dim file As FileInfo
Dim fileCounter = 0
For Each file In fileArray
fileCounter += 1
Dim i As Integer
Dim j As Integer
'Declare Variables for Entity Creation Values
Dim Var1 = ""
Dim Var2 = ""
Dim Var3 = ""
Dim Var4 = ""
Dim Var5 = ""
Dim Var6 = ""
Dim Var7 = ""
'Declare Variable for the Message class
Dim Message = New Message
'Create a FileStream from the file saved in the MessagesFiles folder
Dim fs As New FileStream(Server.MapPath("~/598/" + file.Name), FileMode.Open, FileAccess.Read)
xmlDoc.Load(fs)
fs.Close()
xmlNodeList = xmlDoc.GetElementsByTagName("ieXMLDocument")
'Process the Header Message
For i = 0 To xmlNodeList.Count - 1
For j = 0 To xmlNodeList(i).ChildNodes(0).Attributes.Count - 1
'Set the relevant variable according to the header attributes
Select Case xmlNodeList(i).ChildNodes(0).Attributes(j).Name
Case "Var1" : Var1 = xmlNodeList(i).ChildNodes(0).Attributes(j).Value
Case "Var2" : Var2 = xmlNodeList(i).ChildNodes(0).Attributes(j).Value
Case "Var3" : Var3 = xmlNodeList(i).ChildNodes(0).Attributes(j).Value
Case "Var4" : Var4 = xmlNodeList(i).ChildNodes(0).Attributes(j).Value
Case "Var5" : Var5 = xmlNodeList(i).ChildNodes(0).Attributes(j).Value
Case "Var6" : Var6 = xmlNodeList(i).ChildNodes(0).Attributes(j).Value
End Select
Next
Next
'Set the MessageHeader attributes
marketMessage.CreatedOn = Date.Today
marketMessage.Var4 = DateTime.Parse(Var4)
marketMessage.Var2 = Var2
marketMessage.Var3 = Var3
marketMessage.Var6 = Var6
marketMessage.Var1 = Var1
marketMessage.Var5 = Var5
marketMessage.fileName = file.Name
'Add Message class to database context
db.Messages.Add(Message)
Try
db.SaveChanges()
Catch ex As DbEntityValidationException
System.Diagnostics.EventLog.WriteEntry("Application", "There were validations errors while attempting to save a Message for the xml file named : " + file.Name, EventLogEntryType.Error)
For Each validationErrors In ex.EntityValidationErrors
For Each validationError In validationErrors.ValidationErrors
System.Diagnostics.EventLog.WriteEntry("Application", "Message Validation Error : " + validationError.ErrorMessage, EventLogEntryType.Error)
Next
Next
End Try
Process598(xmlDoc, Message)
System.IO.File.Delete(Server.MapPath("~/598/" + file.Name)
If fileCounter = 5 Then
Return RedirectToAction("Backlog598")
End If
Next
Return Nothing
End Function
此代码命中控制器并在处理完5个文件并在处理完5个文件时删除每个文件后控制器然后被调用,好像我不断运行它会因为读取量而变得非常慢,所以我我决定这样做。
到目前为止,它正在处理63 x 5条记录,总计315条记录,但随后控制器没有被击中。如果我让它在夜间运行,那么它将处理另一组记录。如果我为其他较小的文件每次保存有50条记录,那么它会在停止之前处理3150。
这会阻止某些iis或浏览器限制停止运行所有文件吗?
答案 0 :(得分:0)
Google Chrome重定向循环错误导致了问题,因为它检测到这是一个无限循环