任务数据流,可以从完成状态更改数据块吗? [英] Task Dataflow, can a data block be changed from completion state?

查看:53
本文介绍了任务数据流,可以从完成状态更改数据块吗?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想知道是否可以更改数据块的完成状态?

例如,我标记了一个 var block = new BufferBlock< int>(); 数据块,其中包含 block.Complete().该块链接到其他数据块.我想知道是否可以通过将 block 的完成状态更改回其原始!complete状态来使其再次运行.

如果不可能,那么如何执行多个运行(包括完成),而不必a)取消链接所有块,b)重新实例化所有块,以及c)再次重新链接所有块?

有什么想法可以减轻运行数据流周期的任务,包括完成整个链下的每个块而不必重新创建整个框架?

谢谢

解决方案

不,您不能不完整"完成的数据流块.我认为您应该做的是在每条消息中添加一个标志,说明是否是运行中的最后一条消息.为了使使用起来更简单,您可以创建一组辅助方法,例如:

 公共静态TransformBlock< Tuple< TInput,bool>,Tuple< TOutput,bool>CreateEnhancedTransformBlock< TInput,TOutput>(Func< TInput,TOutput>变换){返回新的TransformBlock< Tuple< TInput,bool> ;, Tuple< TOutput,bool>(元组=>Tuple.Create(transform(tuple.Item1),tuple.Item2));} 

这样,您输入一个仅处理 TInput TOuput transform 委托,并且标志与每个消息一起传输./p>

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

解决方案

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.

这篇关于任务数据流,可以从完成状态更改数据块吗?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆