Task Dataflow, can a data block be changed from completion state?

前端 未结 1 1819
挽巷
挽巷 2021-01-12 20:50

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();

相关标签:
1条回答
  • 2021-01-12 21:01

    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.

    0 讨论(0)
提交回复
热议问题