【发布时间】:2016-07-18 19:38:28
【问题描述】:
我正在尝试使用 Parrallel For each 循环超过 100 000 行的数据表。在大约 25 000 次迭代中一切正常。我没有收到任何错误,并且我看到应用程序仍在运行,但它有点阻塞并且没有任何反应。我试图将循环封装在 factory.startnew 中,但在大约 5000 次迭代时我会无缘无故地获得随机中止预期。
Dim lstExceptions As New ConcurrentQueue(Of Exception)
Dim options As New ParallelOptions
options.MaxDegreeOfParallelism = 3
Parallel.ForEach(ReservationReportDS.Tables(0).AsEnumerable(), options,
Sub(row)
Try
Dim tmpRow As DataRow = CType(row, DataRow)
Dim ReservationID As Integer = tmpRow.Field(Of Integer?)("autNoReservation")
Dim customerID As Integer = tmpRow.Field(Of Integer?)("CustomerID")
Dim VehiculeID As Integer = tmpRow.Field(Of Integer?)("autNoVehicule")
Dim bill As New BillingPath()
bill.Calculate_Billing(ReservationID, customerID, VehiculeID)
Catch err As Exception
lstExceptions.Enqueue(err)
End Try
End Sub
)
If (lstExceptions.Count > 0) Then
Throw New AggregateException(lstExceptions)
End If
Catch errAgg As AggregateException
For Each ex As Exception In errAgg.InnerExceptions
Log(Log_Billing_UI, "", System.Reflection.MethodBase.GetCurrentMethod().Name & GetExceptionInfo(ex))
Next
Catch ex As Exception
Log(Log_Billing_UI, "", System.Reflection.MethodBase.GetCurrentMethod().Name & GetExceptionInfo(ex))
End Try
【问题讨论】:
-
能否添加错误堆栈跟踪
-
1)
bill.Calculate_Billing是否写入数据集? 2)经过精心设计和研究,设计了一个数据库来为这类事情工作,因此它可能是一个不错的选择。此外,数据库中的数据是持久的。 -
没有错误,只是阻塞。在没有线程的情况下使用相同的数据可以正常工作。 1) 是的 Calculate_Billing 将在 95% 的时间内执行 1 次插入,5% 为 2 次或 3 次。但调用会进行多次选择(至少 10 次)
标签: asp.net vb.net parallel-processing task-parallel-library