Skip to content

Parallel.ForEachAsync with BlockingCollection #58680

Discussion options

You must be logged in to vote

Stephen thanks for the reply. My initial ask was ill formulated. In any case I'll be looking into leveraging Channels.

To clarify -- GetConsumingEnumerable() is indeed the functionality that we need, but you warn of performance hits in this post:

First, BlockingCollection’s GetConsumingEnumerable implementation is using BlockingCollection’s internal synchronization which already supports multiple consumers concurrently, but ForEach doesn’t know that, and its enumerable-partitioning logic also needs to take a lock while accessing the enumerable. As such, there’s more synchronization here than is actually necessary, resulting in a potentially non-negligable performance hit. Second, the par…

Replies: 2 comments 2 replies

Comment options

You must be logged in to vote
0 replies
Comment options

You must be logged in to vote
2 replies
@stephentoub
Comment options

@woutervanranst
Comment options

Answer selected by woutervanranst
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Category
Q&A
Labels
None yet
2 participants