ReSharper
 
Get ReSharper
Get your hands on the new features ahead of the release by joining the Early Access Program for ReSharper 2025.1! Learn more

ConfigureAwait analysis

Last modified: 25 September 2024

In the code that relies on the asynchronous programming model (async/await keywords), ConfigureAwait() calls are often used to manage the synchronization context.

The way ConfigureAwait() calls work and their usage scenarios are explained in detail in this Microsoft .NET Blog article as well as in many other posts that you can find on the Internet, but the usage advice for ConfigureAwait() boils down to the following:

  • To improve performance and avoid potential deadlocks, use ConfigureAwait(false) in any non-UI code. The exception here is app-level code, such as Windows Forms, WPF, and ASP.NET.

  • ConfigureAwait(true) corresponds to the default behavior and does nothing meaningful, therefore such calls can be safely omitted.

To analyze usages of ConfigureAwait(), ReSharper needs to know whether it is application-level code or general-purpose library code. By default, the ConfigureAwait analysis is disabled and you need to enable the analysis in each project choosing one of the two modes:

  • Library mode — ReSharper will suggest adding ConfigureAwait(false) calls to awaitables.

  • UI mode — ReSharper will report ConfigureAwait(true) calls as redundant.

The ConfigureAwait analysis relies on two code inspections: Redundant 'ConfigureAwait(true)' in the UI mode and Missing '.ConfigureAwait(false)' in library code in the Library mode. Make sure that these inspections are enabled on the Code Inspection | Inspection Severity page of ReSharper options Alt+R, O.

To fine-tune the analysis, you can enable it in a project and then suppress these inspections in places that should be ignored.