Created
September 18, 2012 22:37
-
-
Save naraga/3746433 to your computer and use it in GitHub Desktop.
BlockingCollection demo
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
class Program | |
{ | |
// BlockingCollection - demo (approaching Q3) | |
static void Main(string[] args) | |
{ | |
var coll = new BlockingCollection<string>(); | |
Task.Run(() => | |
{ | |
Thread.Sleep(1000); | |
coll.TryAdd(DateTime.Now.ToString(CultureInfo.InvariantCulture)); | |
}).ContinueWith(task => | |
{ | |
Thread.Sleep(1000); | |
coll.TryAdd(DateTime.Now.ToString(CultureInfo.InvariantCulture)); | |
}).ContinueWith(task => | |
{ | |
coll.CompleteAdding(); | |
}); | |
foreach (var item in coll.GetConsumingEnumerable()) | |
{ | |
Console.WriteLine(item); | |
} | |
Console.WriteLine("press any key"); | |
Console.ReadLine(); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment