Batch Block
Batch Block Characteristics
- Has input and output
- Takes as a parameter the size of the Batch
- Usually, increase performance
- Output is an array of input type
Batch Block will group the data into batches and will return them in the form of an Array of the type of input. The Batch Block size will group the items for each batch to process. If there are available spots inside the Batch, but we are short on the amount of the items we supplied them, the Batch will await and hold the item until we fill up the available spots.
Batch Block number vs number items
Let's say we have a Backblock<int>(3) that we supply them with 10 integers. The batch Block will process the 9 of them and will hold the last one until we provide them with another two. Until this happens we will be short of an item. In this scenario, we need to tell the Batch that we do not have other items. That will process any remaining items inside the Batch. This is achieved by using the Complete function. Mind the exceptions when using the Complete, use the TryReceive() function.
Complete function to process remaining Batch items
var batch = new BatchBlock<int>(3);
for (int i=0; i<10; i++)
{
batch.Post(i);
}
batch.Complete(); // We are done, process the last items.
Complete operation will force Batch to process the remaining items even if the items are less than the maximum size.
Write to Batch when it is in the Completed State
It is not possible to write into a Batch that is in a Completed State. The item will be ignored.
No files yet, migration hasn't completed yet!