我仍然对TPL DataFlow感到厌倦,所以请耐心等待。ActionBlock是否可以链接到另一个ActionBlock,其中包含更多参数?
我的应用程序需要并行执行队列,同时保持其顺序。这导致我到DataFlow库和我想要做的。我想知道是否有一种方法可以将一个ActionBlock链接到另一个ActionBlock,而第二个从第一个ActionBlock的值开始操作。
伪例如:
var block1 = new ActionBlock<ByteBuffer>(buffer => {
// code generating a hash of the byte buffer to pass to next block
ulong hash = generateHash(buffer);
// this is what i would like to pass to the next ActionBlock
var tup = Tuple<ByteBuffer, ulong>(buffer, along);
}, dataFlowOpts);
var block2 = new ActionBlock<Tuple<ByteBuffer, ulong>(tup => {
/* code to act on the buffer and hash */
}, dataFlowOpts);
block1.LinkTo(block2); // Is there something like this that would use the correct params?
正是我试图做可能吗?这甚至有意义吗?我将它们分成两个ActionBlocks
的原因是我想在另一个代码路径中重用block2(以不同的方式散列不同ByteBuffer
的内容)。
也许有更好的方法吗?真的,我只是试图散列对象,因为它们以并发方式进入,同时保留FIFO顺序,因为它太慢而无法同步散列这些对象。
你看过使用Rx--微软的Reactive Framework吗? (NuGet“System.Reactive”) – Enigmativity