鉴于
以下代码的输出为:000000000011111111112222222222
热门更改代码以生成下一个输出:012012012012012012012012012012
?
var executionDataflowBlockOptions =
new ExecutionDataflowBlockOptions() {
MaxDegreeOfParallelism = 3, EnsureOrdered = false, BoundedCapacity = 30 };
var testData =
Enumerable
.Range(0, 3)
.Select(o => Enumerable.Repeat(o, 10));
var inputBlock =
new TransformManyBlock<IEnumerable<int>, int>(
collectionOfItems => collectionOfItems,
executionDataflowBlockOptions);
var processBlock =
new ActionBlock<int>(
number =>
{
Thread.Sleep(100);
Console.Write(number);
},
executionDataflowBlockOptions );
inputBlock
.LinkTo(processBlock);
foreach (var item in testData)
{
await inputBlock.SendAsync(item);
}
终于找到了这个选项(感谢JSteward)。我用了 Microsoft.Tpl.Dataflow (看起来已过时)而不是 System.Threading.Tasks.Dataflow 。不知道为什么nuget搜索会让他们陷入如此奇怪的秩序。
无论如何添加此选项会更改结果。有时它输出000000000022222222221111111111(更改订单组),更改BoundedCapacity = 30某时输出这样的结果:210202222222020000000111111111或201012222222212111111001000000,这要好得多,但结果仍然可以更随机