在.NET 4.5异步/等待的简要说明 [英] Brief explanation of Async/Await in .Net 4.5

查看:103
本文介绍了在.NET 4.5异步/等待的简要说明的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

如何异步任务(异步/等待)在.NET 4.5的工作?

How does Asynchronous tasks (Async/Await) work in .Net 4.5?

一些示例code:

private async Task<bool> TestFunction()
{
  var x = await DoesSomethingExists();
  var y = await DoesSomethingElseExists();
  return y;
}

请问第二个等待语句被执行马上或之后的第一个等待回报?

Does the second await statement get executed right away or after the first await returns?

推荐答案

的await 直到操作完成暂停方法。所以第二个等待后会得到执行的第一个等待的回报。

await pauses the method until the operation completes. So the second await would get executed after the first await returns.

有关详细信息,请参阅我的 异步 / 等待介绍或的官方FAQ

For more information, see my async / await intro or the official FAQ.

这篇关于在.NET 4.5异步/等待的简要说明的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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