I use ThreadPool to queue 1000 work items
While(reading in data for processing) { args = some data that has been read; ThreadPool.QueueUserWorkItem(new WaitCallback(threadRunner), args); }
This works very well, however, since the main thread of the request queue is faster than they are being processed, memory is slowly being consumed.
I would like to do something similar to the following to disperse the queue when the queue grows
Thread.Sleep(numberOfItemsCurrentlyQueued);
This will increase the latency while increasing the queue.
Is there a way to find out how many items are in the queue?
multithreading c # threadpool
Perrin255
source share