Best practice dictates that ConfigureAwait(false) should always be used in library code, unless the async operation specifically needs to resume on the original SynchronizationContext. So I think it would be useful to create an analyzer for this.
- Level: not sure whether the level should be Information or Warning.
- Code fix: obviously, call
ConfigureAwait(false) on the awaited task
Scenario
becomes
await FooAsync().ConfigureAwait(false);
Another thing to consider: should the analyzer warn only on the first awaited task in the method, or all of them? Unless I'm mistaken, if ConfigureAwait(false) is used on the first await, it's not necessary to use it on the others, since we have already "lost" the SynchronizationContext, so there isn't a SC to capture anyway.
Diagnostic Id: CC0070
Severity: Hidden (Refactoring)
Category: Reliability
Best practice dictates that
ConfigureAwait(false)should always be used in library code, unless the async operation specifically needs to resume on the originalSynchronizationContext. So I think it would be useful to create an analyzer for this.ConfigureAwait(false)on the awaited taskScenario
becomes
Another thing to consider: should the analyzer warn only on the first awaited task in the method, or all of them? Unless I'm mistaken, if
ConfigureAwait(false)is used on the firstawait, it's not necessary to use it on the others, since we have already "lost" theSynchronizationContext, so there isn't a SC to capture anyway.Diagnostic Id:
CC0070Severity:
Hidden(Refactoring)Category:
Reliability