I have a List of URLs which I have to call and do some work on. This already works fine but the List is very large and execution takes very long.
I think I could speed up the programm by working on 5 Urls at the same time as a huge part of the executiontime is probaply the programm waiting for the Urls serverresponse.
I have a List of URLs
List<string> urls = getmyurls();
And then I'm iterating through them
for (int i = 0; i < links.Count; i++)
{
List<string> result = dosomework(urls.ElementAt(i))
urls.AddRange(result);
}
Sometimes I get some additional Urls returned which have to be processed too.
(Code is an example, my actual programm is structured a little bit diffrent. It's a minimal example to explain my problem.)
What I want is five threads running the function "dosomework" at the same time. Whenever one of them is finished I want it to start on the next URL.
Also: How many threads would you run?