为什么在调用 63 次后循环停止?它应该运行到最后但在 63 次调用后停止 90 分钟
Why does loop stop after being called 63 times? It should run to the end but stops for 90 mins after 63 calls
我有一个 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 个文件并在处理完每个文件后删除了每个文件后,访问了控制器并遍历了文件夹,然后调用控制器,就好像我让它持续运行一样,由于读取量和所以我决定这样做。
到目前为止,它正在处理 63 x 5 条记录,总共 315 条记录,但随后控制器没有被击中。如果我让它在一夜之间运行,那么它将处理另一组记录。如果我每次保存 50 条记录(我为其他较小的文件所做的),那么它会在停止前处理 3150 条记录。
这会不会是某种 iis 或浏览器限制停止运行所有文件?
Google Chrome 重定向循环错误导致了问题,因为它检测到这是一个无限循环
我有一个 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 个文件并在处理完每个文件后删除了每个文件后,访问了控制器并遍历了文件夹,然后调用控制器,就好像我让它持续运行一样,由于读取量和所以我决定这样做。
到目前为止,它正在处理 63 x 5 条记录,总共 315 条记录,但随后控制器没有被击中。如果我让它在一夜之间运行,那么它将处理另一组记录。如果我每次保存 50 条记录(我为其他较小的文件所做的),那么它会在停止前处理 3150 条记录。
这会不会是某种 iis 或浏览器限制停止运行所有文件?
Google Chrome 重定向循环错误导致了问题,因为它检测到这是一个无限循环