.Net 4.5 中的 Async/Await 简述 [英] Brief explanation of Async/Await in .Net 4.5

查看:28
本文介绍了.Net 4.5 中的 Async/Await 简述的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

异步任务 (Async/Await) 在 .Net 4.5 中如何工作?

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

一些示例代码:

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

第二个 await 语句是立即执行还是在第一个 await 返回之后执行?

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

推荐答案

await 暂停方法直到操作完成.所以第二个 await 会在第一个 await 返回后执行.

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

有关更多信息,请参阅我的async/await 介绍官方常见问题.

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

这篇关于.Net 4.5 中的 Async/Await 简述的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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