Created
February 23, 2017 23:49
-
-
Save fgasperij/f8994be35da87ccb63e1970b86190d83 to your computer and use it in GitHub Desktop.
BroadcastBlock behavior test
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.Linq; | |
using System.Threading.Tasks.Dataflow; | |
using System.Threading; | |
namespace ConsoleApplication1 | |
{ | |
class Program | |
{ | |
static void Main(string[] args) | |
{ | |
BufferBlock<int> A = new BufferBlock<int>( new DataflowBlockOptions() { BoundedCapacity = 10 }); | |
BroadcastBlock<int> B = new BroadcastBlock<int>((n) => n, new DataflowBlockOptions() { BoundedCapacity = 10 }); | |
TransformBlock<int, int> C1 = new TransformBlock<int, int>( | |
(n) => | |
{ | |
Thread.Sleep(TimeSpan.FromMilliseconds(1000)); | |
Console.WriteLine($"B: Event {n} is going through."); | |
return n; | |
}, | |
new ExecutionDataflowBlockOptions() { BoundedCapacity = 2 }); | |
TransformBlock<int, int> C2 = new TransformBlock<int, int>( | |
(n) => | |
{ | |
Thread.Sleep(TimeSpan.FromMilliseconds(1000)); | |
Console.WriteLine($"C: Event {n} is going through."); | |
return n; | |
}, | |
new ExecutionDataflowBlockOptions() { BoundedCapacity = 2 }); | |
BufferBlock<int> D = new BufferBlock<int>(); | |
A.LinkTo(B); | |
B.LinkTo(C1); | |
B.LinkTo(C2); | |
C1.LinkTo(D); | |
C2.LinkTo(D); | |
foreach (int i in Enumerable.Range(0, 20)) | |
{ | |
A.Post(i); | |
} | |
Console.ReadKey(); | |
} | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment