Quantcast
Channel: VBForums - Visual Basic .NET
Viewing all articles
Browse latest Browse all 27348

VS 2010 Looking for a replacement of the BlockingCollection class.

$
0
0
Hi, I'm currently using the BlockingCollection class for my Producer/Consumer code and it works perfectly, except it uses a ridiculous amount of memory. The maximum capacity has been set to 10 and each item is 500kB, but with 5MB of data it uses between 70MB and 120MB of memory, which is unacceptable to me. I know this was done on purpose and that it keeps a reference to the used items in case one of the Consumer threads is enumerating the queue. This behavior seems to be fixed in .NET Framework 4.5, so it nulls out items if no Consumer threads are enumerating the queue, but I'd like to target 4.0, because 4.5 is not available for Windows XP.

Is there any replacement available that works exactly the same or is it possible to write my own class with SyncLock and WaitHandles? I'm looking for similar functionality with a maximum capacity, Add() method blocking current Producer thread if capacity has been reached, Take() method blocking the current Consumer thread if there are no items in the queue.

Viewing all articles
Browse latest Browse all 27348

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>