I have a very simple process that I am trying to figure out how to use Task.WhenAll to download multiple pages using HttpClient, but if any of the urls throws an exception, even the one that succeeded dont seem to give me the content page.
- Take a list of urls
- Use
HttpClient.GetStringAsync - Process the ones that succeeded
- Get list of all the urls that failed (this might make things messy, if so this is not 100% a requirement)
Here is my code, how can i make it so that if any fail, the remaining will be in pages
urls is List<string> contains list of urls
try
{
var tasks = urls.Select(x => httpClient.GetStringAsync(x));
var pages = await Task.WhenAll(tasks);
//pages will be an array of all the ones that got download without errors
}
catch (Exception e)
{
//not sure how to properly get the ones that failed
Console.WriteLine(e);
}