Created
November 19, 2013 22:25
-
-
Save kadukf/7553682 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
private static readonly BufferBlock<string> Buffer = new BufferBlock<string>(); | |
static void Main(string[] args) | |
{ | |
Enumerable.Range(0, 100).ToList().ForEach(i => Buffer.SendAsync("Mesage #" + i)); | |
var consumer = new ActionBlock<string>(s => Process(s), new ExecutionDataflowBlockOptions { MaxDegreeOfParallelism = 5 }); | |
Buffer.LinkTo(consumer); | |
Buffer.Completion.ContinueWith(t => consumer.Complete()); | |
Console.WriteLine("Running"); | |
Console.ReadLine(); | |
Buffer.Complete(); | |
consumer.Completion.Wait(); | |
Console.WriteLine("Completed"); | |
Console.ReadLine(); | |
} | |
private static void Process(string message) | |
{ | |
Thread.Sleep(250); | |
string msg = Thread.CurrentThread.ManagedThreadId + " : " + message; | |
Console.WriteLine(msg); | |
//messages.Add(msg); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment