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

孤人 提交于 2019-12-01 03:57:09

问题


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


回答1:


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.



来源:https://stackoverflow.com/questions/15967903/task-dataflow-can-a-data-block-be-changed-from-completion-state

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!