I have a long work
var works = ...
List<FormatObject> ret = new List<FormatObject>();
foreach (var w in works)
{
l.AddRange(await Info.GetInfo(w));
}
return Ok(ret);
It's took approximately 76 seconds.
I tried with parallel Task.WhenAll:
var works ...
var ret = await Task.WhenAll(works.Select(Info.GetInfo));
return Ok(ret);
It's also took approximately 76 seconds. So Task.WhenAll is not faster than foreach loop. I thought Task.WhenAll does the work in parallel, so should be faster than foreach which do sequentially. What was I wrong? How can I execute my work in parallel and get the result returned in just one second?