c# - TPL Dataflow. Cannot attach BatchBlock to ActionBlock. Type argument cannot be inferred from usage? -


i have batch block as

var batchblock = new batchblock<ienumerable<string>>(10000,                                                            new groupingdataflowblockoptions                                                                {                                                                 cancellationtoken = cancellationtoken,                                                                 taskscheduler = taskscheduler                                                                }                                                      ); 

and actionblock

var actionblock = new actionblock<ienumerable<string>>(enumerable =>                                                        {                                                             (var = 0;                                                                 < enumerable.count();                                                                 i++)                                                            {                                                                file.appendalltext(@"d:\test.log",                                                                  enumerable.elementat(i));                                                             }                                                        }); 

when try attach them as

batchblock.linkto(actionblock);

i error saying the type arguments method system.threading.tasks.dataflow.dataflowblock.linkto<toutput>(system.threading.tasks.dataflow.isourceblock<toutput>, system.threading.tasks.dataflow.itargetblock<toutput>)' cannot inferred usage. try specifying type arguments explicitly

and same error when this..

batchblock.linkto((actionblock<ienumerable<string>>)actionblock);

however, compiler doesn't complains when instead of attaching create new actionblock in constructor` such as

batchblock.linkto(new actionblock<ienumerable<string>[]>(enumerable => { /* log file */ })); 

can tell me doing wrong? why not letting me attach actionblock batchblock???

the type signature linkto extension method should shed light on what's wrong:

linkto<toutput>(isourceblock<toutput>, itargetblock<toutput>) 

you're specifying batchblock<t> source, , actionblock<t> target, generic type t being ienumerable<string>. however, former implements isourceblock<t[]>, whilst latter implements itargetblock<t>; thus, incompatible being specified arguments linkto method, expects them have same type.

to fix this, need change signature (and implementation) of actionblock to:

var actionblock = new actionblock<ienumerable<string>[]>(enumerables => ...                                                   // ^ accept array of enumerables  

Comments

Popular posts from this blog

html5 - What is breaking my page when printing? -

html - Unable to style the color of bullets in a list -

c# - must be a non-abstract type with a public parameterless constructor in redis -