Created
April 7, 2013 14:07
-
-
Save svick/5330625 to your computer and use it in GitHub Desktop.
This file contains 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
Action A2 executing with value 2 | |
Action A1 executing with value 1 | |
Action A3 executing with value 3 | |
Action A2 executing with value 5 | |
Action A1 executing with value 4 | |
Action A3 executing with value 6 | |
Action A2 executing with value 8 | |
Action A1 executing with value 7 | |
Action A3 executing with value 9 | |
Action A1 executing with value 10 |
This file contains 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
using System; | |
using System.Threading; | |
using System.Threading.Tasks; | |
using System.Threading.Tasks.Dataflow; | |
namespace Dataflow_tmp | |
{ | |
static class Program | |
{ | |
private static void Main() | |
{ | |
BufferBlock<int> bb = new BufferBlock<int>(); | |
ActionBlock<int> a1 = new ActionBlock<int>( | |
a => | |
{ | |
Thread.Sleep(100); | |
Console.WriteLine("Action A1 executing with value {0}", a); | |
}, new ExecutionDataflowBlockOptions { BoundedCapacity = 1 }); | |
ActionBlock<int> a2 = new ActionBlock<int>( | |
a => | |
{ | |
Thread.Sleep(50); | |
Console.WriteLine("Action A2 executing with value {0}", a); | |
}, new ExecutionDataflowBlockOptions { BoundedCapacity = 1 }); | |
ActionBlock<int> a3 = new ActionBlock<int>( | |
(a) => | |
{ | |
Thread.Sleep(50); | |
Console.WriteLine("Action A3 executing with value {0}", a); | |
}, new ExecutionDataflowBlockOptions { BoundedCapacity = 1 }); | |
bb.LinkTo(a1); | |
bb.LinkTo(a2); | |
bb.LinkTo(a3); | |
Task t = new Task( | |
() => | |
{ | |
int i = 0; | |
while (i < 10) | |
{ | |
Thread.Sleep(50); | |
i++; | |
bb.Post(i); | |
} | |
}); | |
t.Start(); | |
Console.Read(); | |
} | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment