I have a blockingcollection of downloads and I would like to have a maximum number of concurrent download I can do, aka a maximum number of concurrent await downloadService.download(release), but the number of items the BlockingCollection should be basically infinite, so let's say I can have 49945 downloads in the BlockingCollection but I should download at the same time just 5 as maximum, whenever a download is finished, it will get another one, in order if possible. Here's my actual code:
BlockingCollection<Download> sendQueue = new BlockingCollection<Download>(new ConcurrentQueue<Download>());
while (true)
{
var release = sendQueue.Take();
ThreadPool.QueueUserWorkItem(async rlZ =>
{
//do whatever you have to do
await downloadService.download(release);
}, release);
}