Skip to content

Instantly share code, notes, and snippets.

@ronnieoverby
Created March 20, 2019 17:11
Show Gist options
  • Save ronnieoverby/1f1750e67ca3c5b7af15b9abc31fd331 to your computer and use it in GitHub Desktop.
Save ronnieoverby/1f1750e67ca3c5b7af15b9abc31fd331 to your computer and use it in GitHub Desktop.
var queue = new BlockingCollection<object>();
// ... meanwhile some other thread is adding to the queue
Task.Run(() =>
{
for (int i = 0; i < 10; i++)
queue.Add(i);
queue.CompleteAdding();
});
foreach (var item in queue.GetConsumingEnumerable())
{
// do something with item
item.Dump();
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment