I'm sure this has a simple fix. When I have the breakpoint on TaskList.Add()
I can see that different batchDeletionRecords
are being passed on to the method, but in the BatchProcess
Method, it's accepting repetitive values.
When I added the arg variable I was able to get proper values for iBatch
. (Saw it here) Didn't work for DataTable
though.
Batcher.Batch()
is supposed to provide batch DataTable
s for the deletionRecords
in the batch of 2. (This thing can be ignored)
var iBatch = 0;
foreach (DataTable batchDeletionRecords in Batcher.Batch(deletionRecords, 2))
{
iBatch++;
var arg = new { _batchDeletionRecords = batchDeletionRecords, _iBatch = iBatch };
TaskList.Add(Task.Run(new Action(() => BatchProcess(arg._batchDeletionRecords.Copy(), arg._iBatch))));
}
BatchProcess()
is a simple method that deletes and prints the values onto the console.