I have a console app, where I need to access some url 200 times, wait for all of the requests to return and work on the 200 results.
I did it like that, in parallel:
var classNameTasks = Enumerable.Range(1, 200).Select(i => webApi.getSplittedClassName()).ToArray();
string[][] splittedClassNames = await Task.WhenAll(classNameTasks);
if (splittedClassNames[0] == null)
result = new TextResult("Error accessing the web");
getSplittedClassName returns a string[], if the internet is off it will return null.
Now, as you can see, after the completion of all the tasks, I do an if to check the content, if its null -> internet issues.
The problem here is that I need to wait for the whole 200 requests to return before I can check the content.
I am looking for a way to right away detect a scenario where there is no internet, and I return null, without having to wait for the 200 requests.