Menu
  • HOME
  • TAGS

Producer Consumer Separate Classes with common BlockingCollection

c#,.net,vb.net,producer-consumer,blockingcollection

Just design your Producer and Consumer classes to accept the BlockingCollection as a constructor parameter. Then, wherever you instantiate these classes, and perhaps even more than one of each, just make sure to pass in the same instance of the BlockingCollection to all producers and consumers. Once you've done that,...

BlockingCollection and Dictionary

c#,dictionary,blockingcollection

Consider using Tuple instead of a Dictionary inside the BlockingCollection. Additionally, you need a call to CompleteAdding() to end the foreach in WriteDataToFiles. BlockingCollection<Tuple<string, List<string>>> bc = new BlockingCollection<Tuple<string, List<string>>>(); private void GenerateDataFiles() { DirectoryInfo directory = new DirectoryInfo(@"D:\Data\"); FileInfo[] array_FileInfo = directory.GetFiles("*.txt", SearchOption.TopDirectoryOnly); Parallel.ForEach(array_FileInfo, fileInfo => {...

Observing changes in a BlockingCollection without consuming

c#,multithreading,concurrency,producer-consumer,blockingcollection

In case you end up using my comment Put a dummy item in the collection that wakes up the producer ...

Add items to a BlockingCollection

c#,task-parallel-library,blockingcollection

I suppose that you can use the Tuple class (http://msdn.microsoft.com/en-us/library/system.tuple.aspx), like this: var ChannelQueue = new BlockingCollection<Tuple<ChannelResource, String>>(); ChannelResource ChanResource = TelephonyServer.GetChannel(); MyApplication.ChannelQueue.TryAdd(Tuple.Create(ChanResource, "someString")); ...

Creating a file pickup process with a Blocking Collection

c#,multithreading,blockingcollection

I think you don't need to stop and start your producers and consumers. The BlockingCollection can block the producers if it reaches a maximum capacity and block the consumers if it is empty. I'd also probably start of with a single BlockingCollection, until profiling shows that I need another one....

How to TryPeek on a BlockingCollection based on a ConcurrentStack

.net,blockingcollection

You should expose the behavior you are looking for by exposing a service that accesses your concurrent stack and blocking collection. That way you can mock the behavior at test time as well. interface IWhateverYourCollectionService { //TryPeak(); //Any other methods that make sense for what your doing. } In this...

BlockingCollection that doesn't try again within 10 seconds

c#,multithreading,fifo,blockingcollection

You could keep two blocking collections: the main one and the "delayed" one. One worker thread would only work on the delayed one, readding them to the main collection. The signature of the rejected collection would be something like: BlockingCollection<Tuple<DateTime, YourObject>> now... If the time is fixed at 10 seconds,...