Task.ConfigureAwait 方法

定义

重载

名称 说明
ConfigureAwait(Boolean)

配置用于等待此 Task情况的 awaiter。

ConfigureAwait(ConfigureAwaitOptions)

配置用于等待此 Task情况的 awaiter。

ConfigureAwait(Boolean)

Source:
Task.cs
Source:
Task.cs
Source:
Task.cs
Source:
Task.cs
Source:
Task.cs

配置用于等待此 Task情况的 awaiter。

public:
 System::Runtime::CompilerServices::ConfiguredTaskAwaitable ConfigureAwait(bool continueOnCapturedContext);
public System.Runtime.CompilerServices.ConfiguredTaskAwaitable ConfigureAwait(bool continueOnCapturedContext);
member this.ConfigureAwait : bool -> System.Runtime.CompilerServices.ConfiguredTaskAwaitable
Public Function ConfigureAwait (continueOnCapturedContext As Boolean) As ConfiguredTaskAwaitable

参数

continueOnCapturedContext
Boolean

true 尝试将延续封送回捕获的原始上下文;否则,为 false.

返回

用于等待此任务的对象。

注解

当异步方法直接等待Task时,任务的延续通常会根据异步上下文,发生在创建任务的同一线程中。 此行为可能会降低性能,并且可能会导致 UI 线程发生死锁。 若要避免这些问题,请调用 Task.ConfigureAwait(false)。 有关详细信息,请参阅 ConfigureAwait 常见问题解答

另请参阅

适用于

ConfigureAwait(ConfigureAwaitOptions)

Source:
Task.cs
Source:
Task.cs
Source:
Task.cs
Source:
Task.cs

配置用于等待此 Task情况的 awaiter。

public:
 System::Runtime::CompilerServices::ConfiguredTaskAwaitable ConfigureAwait(System::Threading::Tasks::ConfigureAwaitOptions options);
public System.Runtime.CompilerServices.ConfiguredTaskAwaitable ConfigureAwait(System.Threading.Tasks.ConfigureAwaitOptions options);
member this.ConfigureAwait : System.Threading.Tasks.ConfigureAwaitOptions -> System.Runtime.CompilerServices.ConfiguredTaskAwaitable
Public Function ConfigureAwait (options As ConfigureAwaitOptions) As ConfiguredTaskAwaitable

参数

options
ConfigureAwaitOptions

用于配置此任务等待执行方式的选项。

返回

用于等待此任务的对象。

例外

options 参数指定无效值。

适用于