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

194 questions
41
votes
4 answers

What is the Difference between ArrayBlockingQueue and LinkedBlockingQueue

What scenarios is it better to use an ArrayBlockingQueue and when is it better to use a LinkedBlockingQueue? If LinkedBlockingQueue default capacity is equal to MAX Integer, is it really helpful to use it as BlockingQueue with default capacity?
Java_Jack
  • 527
  • 1
  • 4
  • 8
29
votes
4 answers

Using BlockingCollection<>: OperationCanceledException, is there a better way?

I'm making use of the (frankly great) BlockingCollection<> type for a heavily multithreaded, high-performance app. There's a lot of throughput through the collection and on the micro-level it's highly performant. However, for each 'batch' it will…
Kieren Johnstone
  • 38,866
  • 13
  • 82
  • 137
18
votes
4 answers

Why does iterating over GetConsumingEnumerable() not fully empty the underlying blocking collection

I have a quantifiable & repeatable problem using the Task Parallel Library, BlockingCollection, ConcurrentQueue & GetConsumingEnumerable while trying to create a simple pipeline. In a nutshell, adding entries to a default BlockingCollection
Eoin Campbell
  • 40,912
  • 17
  • 95
  • 151
13
votes
1 answer

Is the BlockingCollection.TakeFromAny method suitable for building a blocking priority queue?

I need to build a blocking priority queue and my hunch is that TakeFromAny may be the secret ingredient, however the documentation on that method is sparse. What is its purpose / appropriate use? My requirement is that multiple threads will add to…
Ralph Shillington
  • 19,493
  • 20
  • 85
  • 150
11
votes
1 answer

Calling Dispose on an BlockingCollection

I've reused the example producer consumer queue from the C# in a Nutshell book of Albahari (http://www.albahari.com/threading/part5.aspx#_BlockingCollectionT) and a colleague remarked: "Why isn't the Dispose called on the BlockingCollection in the…
Sander
  • 556
  • 1
  • 5
  • 17
11
votes
3 answers

Wait until a BlockingCollection queue is cleared by a background thread, with a timeout if it takes too long?

In C#, I'm wondering if it's possible to wait until a BlockingCollection is cleared by a background thread, with a timeout if it takes too long. The temporary code that I have at the moment strikes me as somewhat inelegant (since when is it good…
Contango
  • 65,385
  • 53
  • 229
  • 279
9
votes
1 answer

How to do async operations in a TPL Dataflow for best performance?

I wrote the following method to batch process a huge CSV file. The idea is to read a chunk of lines from the file into memory, then partition these chunk of lines into batches of fixed size. Once we get the partitions, send these partitions to a…
user330612
  • 2,017
  • 6
  • 29
  • 57
8
votes
2 answers

How to cancel GetConsumingEnumerable() on BlockingCollection

In the following code I'm using the CancellationToken to wake up the GetConsumingEnumerable() when the producer is not producing and I want to break out of the foreach and exit the Task. But I dont see IsCancellationRequested being logged and my…
Spud
  • 233
  • 2
  • 11
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
  • 2,754
  • 3
  • 29
  • 42
7
votes
2 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
  • 10
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
  • 3,471
  • 3
  • 39
  • 69
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
  • 7,200
  • 5
  • 42
  • 78
7
votes
0 answers

How do I use a blockingcollection in the Producer/Consumer pattern when the producers are also the consumers - How do I end?

I have a recursive problem where The consumers do some work at each level of a tree, then need to recurse down the tree and perform that same work at the next level. I want to use ConcurrentBag/BlockingCollection etc to run this in parallel. In…
Jason Coyne
  • 6,179
  • 7
  • 35
  • 64
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,799
  • 2
  • 12
  • 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,529
  • 4
  • 20
  • 40
1
2 3
12 13