.GetAwaiter()和ConfigureAwait()之间的区别 [英] Difference between .GetAwaiter() and ConfigureAwait()

查看:472
本文介绍了.GetAwaiter()和ConfigureAwait()之间的区别的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

谁能告诉我GetAwaiter()ConfigureAwait(false)之间的区别.

Can any one tell me difference between GetAwaiter() and ConfigureAwait(false).

它们都在Async方法中用于解决死锁情况,而ConfigureAwait在不使用同步上下文的情况下完成任务.我正在寻找可以使用GetAwaiter()和使用ConfigureAwait(false)的方案.

Both of them are used in Async method to solve the deadlock situation and ConfigureAwait to complete task without using Synchrnoization context. I'm looking for scenarios where we can use GetAwaiter() and where we use ConfigureAwait(false).

我听说这是我正在构建的库,那么我需要使用ConfigureAwait(false),它会生成Await任务的Configurable Awaitable对象.我可以在单元测试用例项目中使用ConfigureAwait还是应该使用GetAwaiter()来获取等待任务.

I heard if it is library I'm building then I need to use ConfigureAwait(false) which generates Configurable Awaitable object of Await task. Can I use ConfigureAwait in Unittest case project or should use GetAwaiter() which get await task.

推荐答案

从MSDN文档中提取

Task.GetAwaiter 获取用于等待此任务的等待者.在此处查看更多详细信息和此处.

Task.GetAwaiter Gets an awaiter used to await this task. See more details here and here.

Task.ConfigureAwaiter 配置用于等待此任务的等待者.在此处此处

Task.ConfigureAwaiter Configures an awaiter used to await this task. See more details here and here

这篇关于.GetAwaiter()和ConfigureAwait()之间的区别的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆