I'm new to TPL Dataflow and I have it working but I am not sure if I'm using it properly. I have a list of inputs (strings) and I want to process them (all) with a max degree of parallelism and know when it's all complete. Right now I just foreach
through the inputs and call Post
on the ActionBlock
, ignoring the return value. This seems incorrect since it could miss inputs.
My question is: how do I avoid missing items? Is there a built-in block to which I can just give my inputs and it will make sure they are all attempted? (Regardless of success/failure per input.)
The suggestions I've seen basically amount to:
await block.Completion;
Does this account for failed inputs (where Post
or SendAsync
would return false)? The strange thing for me is that it seems like this determination is made when I call Post
and not after, so this Completion
wouldn't even include those items.
I feel like I need basically a retry loop for the inputs that it wasn't able to handle the previous time around, something similar to:
while (items.Count > 0) {
foreach (var item in items) {
if (await block.SendAsync(item)) {
items.Remove(item);
}
}
await block.Completion;
}
block.Complete();
(Except with better loop handling/error checking.)
Is this additional level unnecessary? Or am I wrong conceptually somewhere?