-
Notifications
You must be signed in to change notification settings - Fork 1.7k
Open
Labels
.net/prodPri2Indicates issues/PRs that are medium priorityIndicates issues/PRs that are medium priorityarea-System.Threading.Tasksunspecified/svcuntriagedNew issue has not been triaged by the area ownerNew issue has not been triaged by the area owner
Description
The examples do not document one of the most useful combinations, BlockingCollection and Parallel.ForEach.
There is one undocumented requirement for these two constructs to function well together. Both GetConsumingEnumerable and Parallel.ForEach contain chunking logic, which can prevent items from being processed until CompleteAdding is called.
A Partitioner need to be used with NoBuffering.
var options = new ParallelOptions { MaxDegreeOfParallelism = 4 };
var partitioner = Partitioner.Create(blockingCollection.GetConsumingEnumerable(), EnumerablePartitionerOptions.NoBuffering);
var results = Parallel.ForEach(partitioner, options, item => { /* PROCESS ITEM*/ });
Document Details
⚠ Do not edit this section. It is required for docs.microsoft.com ➟ GitHub issue linking.
- ID: f8df56b2-d5da-8d38-ea9d-7f2fb50f877f
- Version Independent ID: f903165e-d4c7-939f-6679-413310730fe6
- Content: BlockingCollection.GetConsumingEnumerable Method (System.Collections.Concurrent)
- Content Source: [xml/System.Collections.Concurrent/BlockingCollection
1.xml](https://github.com/dotnet/dotnet-api-docs/blob/master/xml/System.Collections.Concurrent/BlockingCollection1.xml) - Service: unspecified
- Product: .net
- GitHub Login: @dotnet-bot
- Microsoft Alias: dotnetcontent
Metadata
Metadata
Assignees
Labels
.net/prodPri2Indicates issues/PRs that are medium priorityIndicates issues/PRs that are medium priorityarea-System.Threading.Tasksunspecified/svcuntriagedNew issue has not been triaged by the area ownerNew issue has not been triaged by the area owner