Question

I would like to know whether it is possible to change the completion state of data blocks?

For example, I marked a var block = new BufferBlock<int>(); data block complete with block.Complete(). The block is linked to other data blocks. I would like to know whether I can make block run again by changing its completion state back to its original !complete state.

If that is not possible how could I perform multiple runs, including completion, without having to a) de-link all blocks, b) re-instantiate all blocks,and c) re-link all blocks again?

Any ideas which may ease the task of running data flow cycles including completing each block down the chain without having to re-create the whole framework?

Thanks

Was it helpful?

Solution

No, you can't “uncomplete” a completed dataflow block. I think what you should do is to add a flag to each message that says whether it's last message in a run. To make it simpler to work with it, you could create set of helper methods like:

public static TransformBlock<Tuple<TInput, bool>, Tuple<TOutput, bool>>
    CreateEnhancedTransformBlock<TInput, TOutput>(Func<TInput, TOutput> transform)
{
    return new TransformBlock<Tuple<TInput, bool>, Tuple<TOutput, bool>>(
        tuple => Tuple.Create(transform(tuple.Item1), tuple.Item2));
}

This way, you enter a transform delegate that deals just with TInput and TOuput and the flag is transfered along with each message.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top