CRR0037 - Task.Wait is used in an async method
This analyzer detects blocking task.Wait methods with the new async/await pattern. Use the new await-friendly methods instead of blocking methods:
Blocking | Await-friendly |
---|---|
task. |
await task |
Task. |
await Task. |
Task. |
await Task. |
Thread. |
await Task. |
Refer to the Task-based Asynchronous Pattern (TAP) MSDN article for more information.
async Task<string> MethodNameAsync(int value, CancellationToken token) {
token.ThrowIfCancellationRequested();
var tasks = new List<Task>();
for (int i = 0; i < 10; i++)
tasks.Add(Task.Delay(100));
Task.WaitAll(tasks.ToArray()); // CRR0037
return value.ToString();
}
Replace the Task.WaitAll call with await Task.WhenAll to fix this issue.