rspec/rules/S3216/csharp/rule.adoc
2021-04-28 18:08:03 +02:00

22 lines
880 B
Plaintext

After an ``++await++``ed ``++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 ``++await++``s 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);
----