如何等待/异步工作的? [英] How does await/async work?

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

问题描述

假设线程A使用等待,等待的东西在线程B.完成,而B是忙于工作负载,A被认为已经标有悬挂点。并在执行流程将继续暂停code座的来电显示的方法。当B完成后,它会通知从悬挂点继续进行。

Suppose thread A use 'await' to wait for something to finish on thread B. while B is busy with the workload, A is considered to have been marked with a 'suspension point'. And the execution flow in A will continue with the 'caller' method of the suspended code block. When B is done, it will notify A to continue from the suspension point.

我的问题是:


  • 什么是上下文信息的内容保持悬挂点?

  • What is the content of the context info kept for the suspension point?

要如何保存上下文信息?

How is the context info be stored?

如何乙通知有关它的完成?

How does B notify A about it's completion?

是一个怎么的上下文信息恢复? (我认为一旦恢复A的上下文信息,A就会从悬挂点自然恢复)

How is the context info of A restored? (I think once the context info for A is restored, A will resume from the suspension point 'naturally')

什么分别是异步的效果,对编译器'等待'。换句话说,有什么特殊的工作做编译器做的帘子后面。

What's the effect of 'async' and 'await' on compiler, respectively. In other words, what special work does the compiler do behind the curtain.

推荐答案

首先,忘记线程。 异步等待都很少做线程和多更多的是与重写方法,使您可以使用连续传球风格更容易。

First, forget threads. async and await have very little to do with threading and much more to do with rewriting methods so you can use continuation passing style more easily.

我建议你阅读我的 异步 / 的await 介绍后,然后跟进的的 MSDN文档(这是相当不错)。这会回答你所有的问题除了最后一个,这是最好的回答乔恩飞碟双向的eduasync博客系列

I recommend you read my async/await intro post and then follow up with the MSDN documentation (which is quite good). That would answer all your questions except the last one, which is best answered by Jon Skeet's eduasync blog series.

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

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