I wanna try something like download from a collection of image in a minimum of 3 concurrent download but, as soon as one of the 3 finished downloading add a new download from the list or must wait to add a new download until a download is finished from 3 concurrent download. How do I implement something like that?
So far I have tried this, but it seems to download all without waiting to be finished from at least 1 from the 3 concurrent download.
List<string> listOfLink = new List<string>();
await Task.Run(() =>
Parallel.ForEach(listOfLink, new ParallelOptions { MaxDegreeOfParallelism = 3 }, async (link, state, index) =>
{
//Download image httpclient
//DownloadImageAsync(link);
}));
I'm not entirely sure you need to use
Paralell.ForEach
here, this answer can explain why better than me re-writing it here: https://stackoverflow.com/a/39796934/5326679However, to answer your actual question, here's what I'd recommend: