© 2026 Hedgehog Software, LLC

TwitterGitHubDiscord
More
CommunitiesDocsAboutTermsPrivacy
Search
Star
Setup for Free
C#C
C#•4y ago•
2 replies
Tandy

❔ How to pause BlockingCollection consumption?

I'm currently enumerating through a
BlockingCollection
BlockingCollection
(with an underlying
ConcurrentQueue
ConcurrentQueue
backing class) using
GetConsumingEnumerable()
GetConsumingEnumerable()
. But I have to pause execution based on some logic, leaving items on the queue, until some other business logic resumes execution. Anyone know the best practice for that? Do I have to bypass
GetConsumingEnumerable()
GetConsumingEnumerable()
and instead write something like below, but adding pause logic?

while (!IsCompleted)
{
  if (TryTake(out var item, Timeout.Infinite))
    yield return item;
}
while (!IsCompleted)
{
  if (TryTake(out var item, Timeout.Infinite))
    yield return item;
}
C# banner
C#Join
We are a programming server aimed at coders discussing everything related to C# (CSharp) and .NET.
61,871Members
Resources

Similar Threads

Was this page helpful?
Recent Announcements

Similar Threads

Stream consumption
C#CC# / help
4y ago
Temporary Pause
C#CC# / help
2y ago
❔ Does BlockingCollection TryTake free the consuming thread to do other things?
C#CC# / help
4y ago