All Downloads are FREE. Search and download functionalities are using the official Maven repository.

org.sonar.plugins.csharp.S3216.html Maven / Gradle / Ivy

There is a newer version: 10.2.0.105762
Show newest version

Why is this an issue?

After an awaited Task has executed, you can continue execution in the original, calling thread or any arbitrary thread. Unless the rest of the code needs the context from which the Task was spawned, Task.ConfigureAwait(false) should be used to keep execution in the Task thread to avoid the need for context switching and the possibility of deadlocks.

This rule raises an issue when code in a class library targeting .Net Framework awaits a Task and continues execution in the original calling thread.

The rule does not raise for .Net Core libraries as there is no SynchronizationContext in .Net Core.

Noncompliant code example

var response = await httpClient.GetAsync(url);  // Noncompliant

Compliant solution

var response = await httpClient.GetAsync(url).ConfigureAwait(false);




© 2015 - 2024 Weber Informatics LLC | Privacy Policy