我有一个TPL Dataflow,当使用谓词来过滤从TransformBlock传递到ActionBlock的项时,它永远不会完成。
如果谓词对任何项返回false,则数据流会挂起。
请问是否有人能提供一些见解以解决这个问题?
如果谓词对任何项返回false,则数据流会挂起。
请问是否有人能提供一些见解以解决这个问题?
// define blocks
var getBlock = new TransformBlock<int, int>(i =>
{
Console.WriteLine($"getBlock: {i}");
return ++i;
});
var writeBlock = new ActionBlock<int>(i =>
{
Console.WriteLine($"writeBlock: {i}");
});
// link blocks
getBlock.LinkTo(writeBlock, new DataflowLinkOptions
{
PropagateCompletion = true
}, i => i == 12); // <-- this predicate prevents the completion of writeBlock
// push to block
var items = new List<int> { 1, 2, 3, 4, 5, 6, 7, 8, 9, 10 };
foreach (var i in items)
{
getBlock.Post(i);
}
// wait for all operations to complete
getBlock.Complete();
await writeBlock.Completion; // <-- application hangs here