I have a list of URLs that I want to download at the same time using HttpClient . The list of URLs can be large (100 or more!)
I have this code:
var urls = new List<string> { @"http:\\www.amazon.com", @"http:\\www.bing.com", @"http:\\www.facebook.com", @"http:\\www.twitter.com", @"http:\\www.google.com" }; var client = new HttpClient(); var contents = urls .ToObservable() .SelectMany(uri => client.GetStringAsync(new Uri(uri, UriKind.Absolute))); contents.Subscribe(Console.WriteLine);
Problem: SelectMany to the use of SelectMany , a large task task is created almost simultaneously. It seems that if the list of URLs is large enough, many tasks set timeouts (I get "Job canceled" ).
So, I thought that there should be a way, perhaps use some kind of Scheduler to limit the number of simultaneous Jobs, not allowing more than 5 or 6 at a given time.
That way, I could receive files that were simultaneously downloaded without running too many tasks that could cause a crash, as of now.
How to do this so that I do not get saturated with a lot of timeouts?
Many thanks.
source share