C#C
C#4y ago
67 replies
Nemesis

Call to async method waiting for execution even without await

I am trying to execute a async method multiple times in parallel. For this I am using the following code:
foreach (var name in Names)
{
  tasks[i] = Method(name);
}
var results = await Task.WhenAll(tasks.Where(task => task != null));

I added a sleep inside the method to verify parallel execution. But when I debug the code, the debug waits for the sleep time on the method call before moving ahead. What am I doing wrong here?
Was this page helpful?