我有这个批处理块
var batchBlock = new BatchBlock<IEnumerable<string>>(10000,
new GroupingDataflowBlockOptions
{
CancellationToken = cancellationToken,
TaskScheduler = taskScheduler
}
);
而这个 ActionBlock 作为
var actionBlock = new ActionBlock<IEnumerable<string>>(enumerable =>
{
for (var i = 0;
i < enumerable.Count();
i++)
{
File.AppendAllText(@"D:\Test.log",
enumerable.ElementAt(i));
}
});
当我尝试将它们附加为
batchBlock.LinkTo(actionBlock);
我收到一条错误消息The type arguments for method System.Threading.Tasks.Dataflow.DataflowBlock.LinkTo<TOutput>(System.Threading.Tasks.Dataflow.ISourceBlock<TOutput>, System.Threading.Tasks.Dataflow.ITargetBlock<TOutput>)' cannot be inferred from the usage. Try specifying the type arguments explicitly
即使我这样做,我也会遇到同样的错误..
batchBlock.LinkTo((ActionBlock<IEnumerable<string>>)actionBlock);
但是,编译器不会抱怨,而不是ActionBlock
在构造函数中附加一个 create a new ,例如
batchBlock.LinkTo(new ActionBlock<IEnumerable<string>[]>(enumerable => { /* log to file */ }));
谁能告诉我我做错了什么?为什么它不让我附上我actionBlock
的batchBlock
???