41 lines
1.2 KiB
Plaintext
41 lines
1.2 KiB
Plaintext
== Why is this an issue?
|
|
|
|
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
|
|
|
|
[source,csharp]
|
|
----
|
|
var response = await httpClient.GetAsync(url); // Noncompliant
|
|
----
|
|
|
|
|
|
=== Compliant solution
|
|
|
|
[source,csharp]
|
|
----
|
|
var response = await httpClient.GetAsync(url).ConfigureAwait(false);
|
|
----
|
|
|
|
|
|
ifdef::env-github,rspecator-view[]
|
|
|
|
'''
|
|
== Implementation Specification
|
|
(visible only on this page)
|
|
|
|
include::message.adoc[]
|
|
|
|
'''
|
|
== Comments And Links
|
|
(visible only on this page)
|
|
|
|
include::comments-and-links.adoc[]
|
|
endif::env-github,rspecator-view[]
|