本文整理汇总了C#中BufferBlock.ToDataflow方法的典型用法代码示例。如果您正苦于以下问题:C# BufferBlock.ToDataflow方法的具体用法?C# BufferBlock.ToDataflow怎么用?C# BufferBlock.ToDataflow使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类BufferBlock
的用法示例。
在下文中一共展示了BufferBlock.ToDataflow方法的1个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: TestDataBroadcaster2
public async Task TestDataBroadcaster2()
{
var random = new Random();
var buffer = new BufferBlock<int>();
int sum1 = 0;
int sum2 = 0;
int sum3 = 0;
var action1 = new ActionBlock<int>(i => sum1 = sum1 + i);
var action2 = new ActionBlock<int>(i => sum2 = sum2 + i);
var action3 = new ActionBlock<int>(i => sum3 = sum3 + i);
buffer.ToDataflow().LinkToMultiple(new []{action1, action2, action3}.Select(a => a.ToDataflow()).ToArray());
for (int j = 0; j < 1000; j++)
{
buffer.Post((int)(random.NextDouble() * 10000));
}
buffer.Complete();
await TaskEx.AwaitableWhenAll(action1.Completion, action2.Completion, action3.Completion);
Console.WriteLine("sum1 = {0} , sum2 = {1}", sum1, sum2);
Assert.AreEqual(sum1, sum2);
Assert.AreEqual(sum1, sum3);
}