سؤال

Questions like this one:

TPL Dataflow, how to forward items to only one specific target block among many linked target blocks?

propose using the DataflowBlock.NullTarget{T} to discard items from a pipeline, e.g.

forwarder.LinkTo(DataflowBlock.NullTarget<SomeType>());

However, if you use NullTarget like this, how do you wait for Completion? Would it not be better to create a discard block:

ITargetBlock<SomeType> discard = DataflowBlock.NullTarget<SomeType>();
forwarder.LinkTo(discard);

and wait for completion on this? i.e.

discard.Completion.Wait()

Or do you not need to wait for completion of a "NullTarget" block, i.e. is it simply throw away and forget?

هل كانت مفيدة؟

المحلول

This isn't documented, but based on my tests, the Completion of a NullTarget will never complete, even after you Complete() or Fault() it.

What this means is that you can't wait on the completion of NullTarget blocks, because the waiting would never end.

مرخصة بموجب: CC-BY-SA مع الإسناد
لا تنتمي إلى StackOverflow
scroll top