If I have a synchronous method "GetStrings()":
private static Task<string[]> GetStrings(IEnumerable<int> ids)
{
var tasks = ids.Distinct().Select(GetString);
return Task.WhenAll(tasks);
}
private static async Task<string> GetString(int stringId)
{
await Task.Delay(15000);
return "hello" + stringId;
}
(which itself calls async method "GetString()")
And I call this synchronous "GetStrings()" method from an async method:
public static async Task Main()
{
var ids = new List<int> { 1, 2, 3 };
await GetStrings(ids);
Console.WriteLine("all done");
Console.ReadLine();
}
What would be the behavioural difference, if GetStrings(
) was actually async? (and performed an await on the Task.WhenAll
)
Would it simply stop Task.WhenAll
from blocking the thread? I've found some production code which looks like this, so I've put together this small example to try and understand what's going. It's difficult to identify the difference though.