c# - How can I specify an unordered Execution Block using the TPL Dataflow Library? -


i want set transformblock processes item in parallel. thus, i'm setting executiondataflowblockoptions.maxdegreeofparallelism > 1. don't care order of messages documentation says:

when specify maximum degree of parallelism larger 1, multiple messages processed simultaneously, , therefore, messages might not processed in order in received. order in messages output block will, however, correctly ordered.

does "correctly ordered" mean if there 1 message in queue needs long processing time, further messages not output until 1 message processed?

and if so, how can specify execution block (for example transformblock) not care ordering? or have specify @ consumption end don't care ordering?

there no such block in library, can create 1 combining actionblock , bufferblock. like:

public static ipropagatorblock<tinput, toutput>     createunorderedtransformblock<tinput, toutput>(     func<tinput, toutput> func, executiondataflowblockoptions options) {     var buffer = new bufferblock<toutput>(options);     var action = new actionblock<tinput>(         async input =>         {             var output = func(input);             await buffer.sendasync(output);         }, options);      action.completion.continuewith(         t =>         {             idataflowblock castedbuffer = buffer;              if (t.isfaulted)             {                 castedbuffer.fault(t.exception);             }             else if (t.iscanceled)             {                 // nothing: both blocks share options,                 // means share cancellationtoken             }             else             {                 castedbuffer.complete();             }         });      return dataflowblock.encapsulate(action, buffer); } 

this way, once item processed actionblock, it's moved bufferblock, means ordering not maintained.

one issue code doesn't observe set boundedcapacity well: in effect, capacity of block twice capacity set in options (because each of 2 blocks has separate capacity).


Comments

Popular posts from this blog

PHPMotion implementation - URL based videos (Hosted on separate location) -

javascript - Using Windows Media Player as video fallback for video tag -

c# - Unity IoC Lifetime per HttpRequest for UserStore -