I have the following list
Dim ordersToUpdate as New List(Of OrderUpdate)
I am using a "For Each" to iterate and update a legacy DB
For Each order In ordersToUpdate
UpdateDB(order)
Next
I am having a LOCKING problem on the DB when the "ordersToUpdate" is large. Instead to puting a Threading.Thread.Sleep to pause, is there a proper way to break the开发者_JAVA百科 list up into sections e.g iterating 100 at a time?
Public Function SplitList(Of T)(ByVal list As List(Of T), ByVal size As Integer) As List(Of List(Of T))
Dim result As New List(Of List(Of T))
For i = 0 To CInt(Math.Ceiling(list.Count / size)) - 1
result.Add(New List(Of T)(list.GetRange(i * size, Math.Min(size, list.Count - (i * size)))))
Next
Return result
End Function
Reference
精彩评论