Skip to content

Instantly share code, notes, and snippets.

@ElemarJR
Created October 5, 2012 18:06
Show Gist options
  • Select an option

  • Save ElemarJR/3841396 to your computer and use it in GitHub Desktop.

Select an option

Save ElemarJR/3841396 to your computer and use it in GitHub Desktop.
static void Main(string[] args)
{
Console.Title = "TPL Dataflow";
var source = new[] {
"elemarjr", "leandronet", "vquaiato",
"juanplopes", "rodrigovidal", "cleytonferrari",
"diogodamiani", "sricanesh", "rodrigokono"
};
var ab1 = new ActionBlock<string>(async s =>
{
await Task.Delay(900);
Console.WriteLine("{0} from action block 1", s);
}, new ExecutionDataflowBlockOptions { BoundedCapacity = 1 });
var ab2 = new ActionBlock<string>(async s =>
{
await Task.Delay(600);
Console.WriteLine("{0} from action block 2", s);
}, new ExecutionDataflowBlockOptions { BoundedCapacity = 1 });
var ab3 = new ActionBlock<string>(async s =>
{
await Task.Delay(300);
Console.WriteLine("{0} from action block 3", s);
}, new ExecutionDataflowBlockOptions { BoundedCapacity = 1 });
var bufferBlock = new BufferBlock<string>();
bufferBlock.LinkTo(ab1);
bufferBlock.LinkTo(ab2);
bufferBlock.LinkTo(ab3);
foreach (var item in source)
bufferBlock.Post(item);
Console.WriteLine("Waiting...");
Console.Read();
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment