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
2
votes
3 answers

How to implement the BlockingCollection.TakeFromAny equivalent for Channels?

I am trying to implement an asynchronous method that takes an array of ChannelReaders, and takes a value from any of the channels that has an item available. It is a method with similar functionality with the BlockingCollection.TakeFromAny…
2
votes
1 answer

How to copy BlockingCollection and edit the new one without editing the origin

I want to copy a BlockingCollection and edit the copy. (dataModelCollection is the copy of DataModelListRaw) When I do this: BlockingCollection dataModelCollection = DataModelListRaw; while (dataModelCollection.TryTake(out _)) { } I…
Andi
  • 48
  • 5
2
votes
1 answer

How to notify failure in producer-consumer pattern using BlockingCollection?

I'm trying to create a lifetime process that batches incoming messages for DB bulk insert. The new message is coming in 1 at a time, in an irregular interval. My solution to this would be something like the producer-consumer pattern using…
2
votes
1 answer

C# RabbitMQ pool/queue approach

I'm trying to create a queue/pool of rabbit mq channels for reuse, which they recommend to do this, but don't provide any approach of how to actually do this! I have this working but ideally I don't want to populate the channels when the constructor…
Andrew
  • 2,571
  • 2
  • 31
  • 56
2
votes
1 answer

BlockingCollection Paged to Disk

I have read about BigQueue and the like to be a durable disk bound queue. Is there anything for c# that is not durable but "pages" queue overflow to disk. I have incoming byte[] after incoming byte[] and don't want to overload the…
maxfridbe
  • 5,872
  • 10
  • 58
  • 80
2
votes
1 answer

Timer vs Thread vs RegisteredWaitHandle for consuming from BlockingCollection

I have a service which talks to around 50 devices over Ethernet using TCP. These devices push data at various speeds (ranging from 50ms to 1500ms). Hence I use BlockingCollection (per device) for queuing the received data and then processing the…
Arctic
  • 807
  • 10
  • 22
2
votes
1 answer

Graceful exit from BlockingCollection.TakeFromAny when adding to collections completed

I wait for available items in two BlockingCollections in a loop using BlockingCollection.TakeFromAny. Items are added to the collections in other theads. At some point I finish adding to the collections and on the next call to TakeFromAny my code…
2
votes
2 answers

BlockingCollection file logging - Thread of a BlockingCollection task automatically aborted

Is BlockingCollection thread safe in every situation ? I am trying to use a BlockingCollection to implement a log system without taking too much of the Main Thread resources. The idea is that it costs only a BlockingCollection.Add() call for the…
Gaël
  • 117
  • 1
  • 2
  • 17
2
votes
1 answer

WebClient does not support concurrent I/O operations - DownloadStringAsync - Scraping

First of all I have read the similar questions and they don't give me a coherent explanation. I use BlockingCollection ClientQueue to provide Webclients. I give them a handling function and start the async scraping : // Create queue of…
losange
  • 335
  • 3
  • 14
2
votes
1 answer

Efficient file writing using BlockingCollection

I have a producer consumer scenario. Producer produces data for BlockingCollection and some other thread consumes it. When consumer takes an item it must write it to a text file. There is no limit how much data can be produced by producer thread so…
Alias
  • 341
  • 2
  • 3
  • 14
2
votes
0 answers

Task that ReadsKey from keyboard doesnt work - Consumer/Producer Pattern

I am implementing a single Producer/Consumer Pattern using BlockingCollection. When i click 'c' from keyboard i want to cancel the operation using CancellationToken. The strange thing is that if i press 'c' as fast as i can after i run the program,…
RoR noob
  • 337
  • 3
  • 11
2
votes
1 answer

multithreading sqldatareader time expired

Here is scenario: I want to insert data to table from server A to server B. The data is very huge, so I will use SqlBulkCopy to do the job. Here is my idea: producer: get all page number consumer: get page number, paging data from server A and…
2
votes
2 answers

c# Blocking Collection and Threading

I'm new to using Blocking Collection and threading and want to make sure I'm following best practice. I'm using a third party API that is not thread safe. I will be making multiple simultaneous requests to the API, so I need to add these requests to…
2
votes
1 answer

Using a BlockingCollection to queue Tasks

I am trying to create a way to queue up Tasks to run, so I have tried to implement it using a BlockingCollection. The problem I find is whenever I try to add the Task, the Task executes. Sample code as below: private void button1_Click(object…
2
votes
0 answers

.NET BlockingCollection All But One Thread Processes Messages

I have a class that uses a blocking collection: public class MessageQueue : IDisposable { private BlockingCollection queue; private MessageHandler messageHandler; private CancellationToken cancellationToken; public…
webteckie
  • 428
  • 5
  • 17