dotnet / dotnet/dotnet-api-docs
https://gist.github.com/sheastrickland/49392be4bb7b2f6b2143
- Lingua principale
- C#
- Stelle
- 949
- Fork
- 1.7k
- Merge medio
- 2g 19h
- PR unite (30g)
- 52
Descrizione
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)](https://docs.microsoft.com/en-us/dotnet/api/system.collections.concurrent.blockingcollection-1.getconsumingenumerable?view=netframework-4.7.2#System_Collections_Concurrent_BlockingCollection_1_GetConsumingEnumerable)
* Content Source: [xml/System.Collections.Concurrent/BlockingCollection`1.xml](https://github.com/dotnet/dotnet-api-docs/blob/master/xml/System.Collections.Concurrent/BlockingCollection`1.xml)
* Service: **unspecified**
* Product: **.net**
* GitHub Login: @dotnet-bot
* Microsoft Alias: **dotnetcontent**
Guida per i contributori
Apri la guida per i contributori
Direzione di ricerca
Inizia con xml/System.Collections.Concurrent/BlockingCollection`1.xml e la pagina API collegata di GetConsumingEnumerable. Aggiungi un esempio che documenti la combinazione di BlockingCollection e Parallel.ForEach, inclusa la necessità di NoBuffering Partitioner mostrata nell’issue. Il lavoro è completato quando la documentazione dell’API spiega perché è necessario e include l’esempio funzionante.
Scritto dal modello di indicizzazione a partire dal testo della issue.
Valutazione
- Stack tecnologico
- csharp
- Ambito
- documentation
- Tipo di issue
- Documentazione
- Difficoltà
- 2/5
- Tempo stimato
- 1-3 ore
- Stato di attività
- Ferma
- Chiarezza
- Specificata chiaramente
- Idoneità per principianti
- 30/100