我仍然對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