How Can I determine the number of items in ThreadPool Queue

前端 未结 2 1648
深忆病人
深忆病人 2021-01-12 11:13

I am using the ThreadPool to queue 1000\'s of workitems

While(reading in data for processing)
{
    args = some data that has been read;
    ThreadPool.Queue         


        
2条回答
  •  不要未来只要你来
    2021-01-12 11:38

    A more manageable abstraction for Producer/Consumer queue is BlockingCollection. The example code there shows how to use Tasks to seed and drain the queue. The queue count is readily available via the Count property.

    If you can, avoid using Sleep to delay production of more items. Have the producer wait on an Event or similar when queue gets too large, and have consumer(s) signal the Event when the queue backlog reaches a threshold where you are comfortable allowing more items to be produced. Always try to make things event-driven - Sleep is a bit of a guess.

提交回复
热议问题