Questions tagged [blockingcollection]

A .Net class that provides blocking and bounding capabilities for thread-safe collections.

A .Net class that provides blocking and bounding capabilities for thread-safe collections.

References

233 questions
8
votes
3 answers

How to wrap ConcurrentDictionary in BlockingCollection?

I try to implement a ConcurrentDictionary by wrapping it in a BlockingCollection but did not seem to be successful. I understand that one variable declarations work with BlockingCollection such as ConcurrentBag, ConcurrentQueue, etc. So, to…
7
votes
3 answers

Usage of Task.WhenAll with infinite Tasks produced by BlockingCollection

I am adding Background Tasks to a Blocking Collection (added in the Background). I am waiting with Task.WhenAll on a Enumerable returned by GetConsumingEnumerable. My question is: Is the overload of Task.WhenAll which receives an IEnumerable…
rudimenter
  • 3,242
  • 4
  • 33
  • 46
7
votes
3 answers

Cancelling BlockingCollection.GetConsumingEnumerable() and processing what's left

I have one process generating work and a second process with a BlockingCollection<> that consumes that work. When I close my program, I need my consumer to stop consuming work, but I still need to quickly log the work that was pending but hadn't…
Jason
  • 156
  • 1
  • 11
7
votes
2 answers

BlockingCollection multiple consumer

I have the following code with one producer thread and multiple consumer threads. Do you know if multiple consumers are thread safe. For example is there any chance that thread 1 is consuming and while do that thread 2 consume in parallel and change…
pantonis
  • 5,601
  • 12
  • 58
  • 115
7
votes
1 answer

Can Bounded BlockingCollections Lose Data During Adds

I have a BlockingCollection(ConcurrentBag, 50000) where I am trying to use a very small Bounded Capacity of 50,000 for the producer threads in order to maximize the number of records I can process in my consumer thread's ConcurrentDictionary. The…
7
votes
1 answer

The .Net Concurrent BlockingCollection has a memory leak?

I'm using a Producer/Consumer Pattern with a System.Collection.Concurrent.BlockingCollection to retrieve data from a database (producer) and create a Lucene Index on the data (consumer). The Producer grabs 10000 records at a time and adds…
NSjonas
  • 10,693
  • 9
  • 66
  • 92
6
votes
2 answers

Concurrent collections and unique elements

I have a concurrent BlockingCollection with repeated elements. How can modify it to add or get distinct elements?
6
votes
3 answers

Scaling Connections with BlockingCollection()

I have a server which communicates with 50 or more devices over TCP LAN. There is a Task.Run for each socket reading message loop. I buffer each message reach into a blocking queue, where each blocking queue has a Task.Run using a…
6
votes
3 answers

Difference between Take/TryTake and Add/TryAdd on a Blocking Collection

I have been trying to get my head around the Blocking Collection and I came across Take() and TryTake() also Add() and TryAdd() I understand that if there are no items to take, Take() will wait till an item is added, similarly with Add() if the…
Muds
  • 4,006
  • 5
  • 31
  • 53
6
votes
2 answers

Running Multiple threads in queue using BlockingCollections

My program has 3 functions. Each function takes a list of Items and fill certain information. For example class Item { String sku,upc,competitorName; double price; } function F1 takes a List and fills upc function F2 takes List (output of F1)…
Subhash Makkena
  • 1,909
  • 2
  • 13
  • 15
6
votes
1 answer

Is it ok to use Pika BlockingConnection in web app?

I'm a little bit confused about BlockingConnection and AsyncoreConnection. I want to send some messages to the RabbitMQ queue from a Django app. Is it ok to do that using a global BlockingConnection object? Thank You.
User
  • 1,978
  • 5
  • 26
  • 47
6
votes
0 answers

How to detect AddingCompleted of a BlockingCollection without race condition and exception?

I'm using a BlockingCollection{T} that's filled from only one thread and consumed by only one thread. Producing and consuming items works fine. The problem is at the end of this operation. The task blocks (as expected) at GetConsumingEnumerable.…
6
votes
2 answers

update an ObservableCollection with a BlockingCollection

I subscribe to a service that will raise an Event when a new element is received, I add this element to a BlockingCollection. I have a second thread running that will loop the BlockingCollection to add/update the element in an observable…
5
votes
2 answers

C# Correctly aborting a always running thread with a BlockingCollection

I am running a thread that has a while(isRunning) { blockingCollection.Take() } First I am setting isRunning to false. Then I call thread.Interrupt which stops the blockingCollection from waiting for new items. After that I call my Dispose…
Thypari
  • 801
  • 1
  • 6
  • 22
5
votes
1 answer

TryTake vs GetConsumingEnumerable

What is the difference between solution 1 and 2, _taskQ is BlockingCollection and I am trying to implement a Producer-Consumer scenario. The BlockingCollection uses the default ConcurrentQueue for internal storage. //Solution 1 foreach (Action…
Helic
  • 907
  • 1
  • 10
  • 25
1
2
3
15 16