What is the Difference Between Awaiter (GetAwaiter) and ContinueWith

大兔子大兔子 提交于 2019-12-23 10:29:09

问题


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

What is the difference?


回答1:


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

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.



来源:https://stackoverflow.com/questions/16306474/what-is-the-difference-between-awaiter-getawaiter-and-continuewith

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!