本文整理汇总了C#中ActionBlock.PostRange方法的典型用法代码示例。如果您正苦于以下问题:C# ActionBlock.PostRange方法的具体用法?C# ActionBlock.PostRange怎么用?C# ActionBlock.PostRange使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类ActionBlock
的用法示例。
在下文中一共展示了ActionBlock.PostRange方法的2个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: TestNullReturnedTasks
public async Task TestNullReturnedTasks()
{
int sumOfOdds = 0;
var ab = new ActionBlock<int>(i => {
if ((i % 2) == 0) return null;
return Task.Run(() => { sumOfOdds += i; });
});
const int MaxValue = 10;
ab.PostRange(0, MaxValue);
ab.Complete();
await ab.Completion;
Assert.Equal(
expected: Enumerable.Range(0, MaxValue).Where(i => i % 2 != 0).Sum(),
actual: sumOfOdds);
}
示例2: TestSchedulerUsage
public async Task TestSchedulerUsage()
{
foreach (bool singleProducerConstrained in DataflowTestHelpers.BooleanValues)
{
var scheduler = new ConcurrentExclusiveSchedulerPair().ExclusiveScheduler;
var sync = new ActionBlock<int>(_ => Assert.Equal(scheduler.Id, TaskScheduler.Current.Id),
new ExecutionDataflowBlockOptions
{
TaskScheduler = scheduler,
SingleProducerConstrained = singleProducerConstrained
});
sync.PostRange(0, 10);
sync.Complete();
await sync.Completion;
var async = new ActionBlock<int>(_ => {
Assert.Equal(scheduler.Id, TaskScheduler.Current.Id);
return Task.FromResult(0);
}, new ExecutionDataflowBlockOptions
{
TaskScheduler = scheduler,
SingleProducerConstrained = singleProducerConstrained
});
async.PostRange(0, 10);
async.Complete();
await async.Completion;
}
}