ReSharper 2024.3 Help

Code inspection: Redundant context capturing with 'ConfigureAwait'

This inspection reports ConfigureAwait(true) calls as redundant in the scope where ConfigureAwait analysis is enabled in the UI mode.

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.

Enable ConfigureAwait analysis and choose its mode

  • To enable ConfigureAwait analysis in a project, right-click the project in the Solution Explorer, select Edit project item properties | ConfigureAwait analysis mode, and then choose Library or UI.

  • To enable ConfigureAwait analysis in the current project, place the caret at any await keyword, press Alt+Enter, select ConfigureAwait analysis and then choose Library or UI.

  • If you use EditorConfig, you can specify the ConfigureAwait analysis mode for a project, a folder, or a file with the following properties: configure_await_analysis_mode = library or configure_await_analysis_mode = ui.

Last modified: 11 February 2024