dotnet / dotnet/docs

Warning CA1849 ignores previous await

Open
#27,150 1 comment 10 reactions 0 assignees View on GitHub
dotnet-fundamentals/svc
Dominant language
No language data
Stars
4.8k
Forks
6.1k
Avg merge
19h 10m
Merged PRs (30d)
268

Description

If a Task is already guaranteed to be completed, this warning makes no sense.
For example:
```
await task.ConfigureAwait(false);
DoSomething(task.Result);
```
Or:
```
await Task.WhenAll(task1, taks2).ConfigureAwait(false);
DoSomething(task1.Result, task2.Result);
```
Both examples rise this warning. The "suggested" way, without assigning any result varibles, would be to await twice, which doesn't make sense and makes the code completely unreadable:
```
await Task.WhenAll(task1, taks2).ConfigureAwait(false);
DoSomething(await task1.ConfigureAwait(false), await task2.ConfigureAwait(false));
```

---
#### Document Details

⚠ *Do not edit this section. It is required for docs.microsoft.com ➟ GitHub issue linking.*

* ID: 4637a020-3411-c088-d05f-28e1a487d7a8
* Version Independent ID: ea5d80fc-2578-a157-6f3c-b85794ab0fa0
* Content: [CA1849: Call async methods when in an async method - .NET](https://docs.microsoft.com/en-us/dotnet/fundamentals/code-analysis/quality-rules/ca1849)
* Content Source: [docs/fundamentals/code-analysis/quality-rules/ca1849.md](https://github.com/dotnet/docs/blob/main/docs/fundamentals/code-analysis/quality-rules/ca1849.md)
* Product: **dotnet-fundamentals**
* GitHub Login: @mahdiva
* Microsoft Alias: **gewarren**

Contributor guide

Open the contributing guide

Assessment

This issue has not been assessed yet.

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.