Created
August 3, 2025 04:17
-
-
Save MattParkerDev/d9bd0be8a5619996b81780be4c6e566f to your computer and use it in GitHub Desktop.
Correct IAsyncDisposable.ConfigureAwait(false) usages
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| // 'using' statement | |
| // if you don't need access to the CancellationTokenRegistration | |
| await using (cancellationToken.Register(() => buildManager.CancelAllSubmissions()).ConfigureAwait(false)) | |
| { | |
| // disposed outside this scope | |
| } | |
| // 'using' statement | |
| // if you need access to the CancellationTokenRegistration | |
| var test = cancellationToken.Register(() => buildManager.CancelAllSubmissions()); | |
| await using (test.ConfigureAwait(false)) | |
| { | |
| // disposed outside this scope | |
| var cts = test.Token; | |
| }; | |
| // 'using' declaration | |
| // if you don't need access to the CancellationTokenRegistration | |
| await using var _ = cancellationToken.Register(() => buildManager.CancelAllSubmissions()).ConfigureAwait(false); | |
| // 'using' declaration | |
| // if you need access to the CancellationTokenRegistration | |
| var test2 = cancellationToken.Register(() => buildManager.CancelAllSubmissions()); | |
| await using var __ = test2.ConfigureAwait(false); | |
| var cts2 = test2.Token; |
Author
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Noting that
await using var _andawait using var __are not true discards, they are variables, hence the need to have different names. There is a discussion around allowingawait using _ = ...here: dotnet/csharplang#8605