سؤال

I have a TransformManyBlock<Tin, Tout> and during run time add consumers (ActionBlocks) through LinkTo(...).

  1. Is TransformManyBlock the correct data flow block to consume elements, transform them, and then output (same number elements output as input) to several consumers (each linked-to consumer consumes identical elements like a broadcast)? I deliberately do not chose a BroadCastBlock because it seems to be unable to transform elements similarly to a BufferBlock.

  2. I like to know how I can unlink consumers (ActionBlocks here) during runtime? LinkTo() does not seem to provide such functionality as far as I can see.

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

المحلول

  1. TransformManyBlock is for transforming one item on the input into multiple items on the output, it has nothing to do with the number of consumers.

    If you want to perform the transformation separately for each target, then that's exactly what cloningFunction in BroadcastBlock is for.

    If you want to perform the transformation once and then send each target the same object, you can combine TransformBlock and BroadcastBlock by linking them together. The item will be transformed by the TransformBlock, and then sent to all targets by the BroadcastBlock.

  2. The return value of LinkTo() is:

    An IDisposable that, upon calling Dispose, will unlink the source from the target.

    This is exactly what you need. Just store the value returned from LinkTo() and then Dispose() it when necessary.

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