什么是之间Awaiter(GetAwaiter)和ContinueWith差异 [英] What is the Difference Between Awaiter (GetAwaiter) and ContinueWith

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

问题描述

在.NET 4.0中,我经常使用Task.ContinueWith。但后来我发现task.GetAwaiter()这似乎有异曲同工之妙。

In .net 4.0, I use Task.ContinueWith regularly. But then I spotted "task.GetAwaiter()" which seems to have the same purpose.

有什么区别?

推荐答案

如果你的目标.NET 4,你会使用 ContinueWith

If you're targeting .NET 4, you'd use ContinueWith.

在一般情况下,你通常不会使用 task.GetAwaiter()。这种方法存在以支持计谋关键字,而不是.NET 4中(它在4.5中加入)的一部分。这是不是你通常直接使用自己,而是把它写成一个部分异步方法。

In general, you wouldn't normally use task.GetAwaiter(). This method exists in order to support the await keyword, and is not part of .NET 4 (it's added in 4.5). This isn't something you'd typically use directly yourself, but instead write it as part of an async method.

这篇关于什么是之间Awaiter(GetAwaiter)和ContinueWith差异的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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