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
5
votes
1 answer

Deadlocks when using BlockingCollection and TPL dataflow together

I've written a sample test that replicates the issue. This is not my actual code, I've tried to write a small repro. If you increase the bounding capacity to the number of iterations effectively giving it no bounding it does not deadlock and if…
5
votes
2 answers

BlockingCollection batching using TPL DataFlow

Is there a way to batch a collection of items from the blocking collection. E.G. I have a messaging bus publisher calling blockingCollection.Add() And a consuming thread which is created like this: Task.Factory.StartNew(() => { …
5
votes
3 answers

Does foreach remove from C# BlockingCollection?

does anyone know if, when iterating on a C# BlockingCollection<>, the elements are taken from the collection, in the same way that BlockingCollection.Take() does for example? BlockingCollection q = new…
nitbix
  • 143
  • 8
5
votes
2 answers

Is the list order of a ConcurrentDictionary guaranteed?

I am using a ConcurrentDictionary to store log-lines, and when I need to display them to the user I call ToList() to generate a list. But the weird thing is that some users receive the most recent lines first in the list, while they should logically…
Maestro
  • 9,046
  • 15
  • 83
  • 116
5
votes
2 answers

Add collection to BlockingCollection

BlockingCollection contains only methods to add individual items. What if I want to add a collection? Should I just use foreach loop? Why BlockingCollection doesn't contain method to add a collection? I think such method can be pretty useful.
Oleg Vazhnev
  • 23,239
  • 54
  • 171
  • 305
4
votes
1 answer

Streaming Data BlockingCollection

On page 88 of Stephen Toub's book http://www.microsoft.com/download/en/details.aspx?id=19222 There is the code private BlockingCollection _streamingData = new BlockingCollection(); //…
TheWommies
  • 4,922
  • 11
  • 61
  • 79
4
votes
4 answers

How to maximize process throughput (C#)?

I want to process some files with maximum throughput. The paths to files are saved in a database. I need to get file paths from the database, change their status to processing, process them, then change their status to either completed or…
4
votes
3 answers

Producer/ Consumer pattern using threads and EventWaitHandle

I guess it is sort of a code review, but here is my implementation of the producer / consumer pattern. What I would like to know is would there be a case in which the while loops in the ReceivingThread() or SendingThread() methods might stop…
4
votes
2 answers

Check for duplicates in Blocking collection

What is the best way to check if an item is existed in the BlockingCollection before trying to add a new one? Basically I do not want duplicates to be added to the BlockingCollection.
4
votes
2 answers

BlockingCollection with async task

I'm trying to correctly model a multi-thread single-producer/multi-consumer scenario where a consumer can ask the producer to get an item, but the producer needs to do a time consuming operation to produce it (think about executing a query or…
andreapier
  • 2,958
  • 2
  • 38
  • 50
4
votes
2 answers

Producer / hybrid consumer in C# using 4.0 framework classes and Blocking Collection

I have a situation in which I have a producer/consumer scenario. The producer never stops, which means that even if there is a time where there are no items in the BC, further items can be added later. Moving from .NET Framework 3.5 to 4.0, I…
4
votes
1 answer

Foreach throwing errors when printing datatable obtained from BlockingCollection in C#

I have hit a stumbling block in my foray into multithreading. I think I know what the problem is but can't determine how to resolve it. But I may be wrong. In summary I have producer and consumer threads. The producer threads collect data from an…
Danrex
  • 1,657
  • 4
  • 31
  • 44
4
votes
0 answers

BlockingCollection with the ability to re-set the maximum number of items at runtime

I have a BlockingCollection that I m using in a classic publish-subscribe type example where the collection works as a buffer. When it reaches N it has to wait for the readers to consume at least one item. This works fine. Now I would like to be…
Yannis
  • 6,047
  • 5
  • 43
  • 62
4
votes
1 answer

Does GetConsumingEnumerable actually remove an item from a BlockingCollection?

The MSDN remarks at http://msdn.microsoft.com/en-us/library/dd267312.aspx state that... "The default collection type for BlockingCollection is ConcurrentQueue" Does this mean that while I am running "GetConsumingEnumerable()" on the collection, the…
Dabloons
  • 1,462
  • 2
  • 17
  • 30
4
votes
2 answers

Is foreach the only way to consume a BlockingCollection in C#?

I'm starting to work with TPL right now. I have seen a simple version of the producer/consumer model utilizing TPL in this video. Here is the problem: The following code: BlockingCollection bc = new…
Girardi
  • 2,734
  • 3
  • 35
  • 50
1 2
3
15 16