何时使用异步等待 [英] when to use async await

查看:72
本文介绍了何时使用异步等待的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

寻找指导我何时使用async和等待的好例子。


aync是否等待运行工作线程或主ui线程中的代码?


它是否会产生新线程?


从async await函数可以更新ui而不用begininvoke吗?


如果我写


await f()


await z()


两个函数并行运行?或者首先等待停止执行直到f()完成?


如何阻止异步方法作为结果下一行方法 将在完成第一个异步等待方法后调用。 只需告诉我代码。


请分享知识。谢谢

解决方案

从最佳做法开始


https://gist.github.com/jonlabelle/841146854b23b305b50fa5542f84b20c


当阅读以下关于使用Async / await的解释时(请务必阅读提示部分)


http://blog.stephencleary.com/2012/02/async-and-await.html


何时考虑到异步,有很多事情要考虑,所以上面应该是一个很好的起点。





Looking for good example which guide me when to use async and await.

Does aync await run the code in worker thread or main ui thread?

Does it spawn new thread?

From async await function can i update ui without begininvoke?

If i write

await f()

await z()

both functions run parallel? Or first await stop the execution until f() comple ?

how to block async method as result next line method  will call after the completion of first async await method.  Just show me with code.

please share knowledge. Thanks

解决方案

Start with best practices

https://gist.github.com/jonlabelle/841146854b23b305b50fa5542f84b20c

When read the following on explainations for using Async/await (make sure to read the tip sections)

http://blog.stephencleary.com/2012/02/async-and-await.html

When considering async there are various things to consider so the above should be a good starting point.


这篇关于何时使用异步等待的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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