Created
October 5, 2012 18:06
-
-
Save ElemarJR/3841396 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| 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