是在编译器严格执行新的C#异步功能 [英] Is the new C# async feature implemented strictly in the compiler

查看:136
本文介绍了是在编译器严格执行新的C#异步功能的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

作为一个C#程序员的兴趣探索,我非常想了解多一点的过程,使新的异步的功能的工作。

As a C# programmer whose interested in exploring "how things work", i am interested in understanding a bit more about the process that makes the new async feature work.

我跟埃里克利珀的优秀文章系列异步:异步的博客文章

I have followed Eric Lippert's excellent article series on async: Async blog posts

我不记得看​​到任何地方提到这个功能的实现(高电平)除了在为我们编译器正在做的大部分工作的事实。

I don't remember seeing anywhere any reference to the implementation of this feature (in a high level) except for the fact the the "compiler is doing most of the work" for us.

时此功能严格意义上的编译器的功能呢?该编译器重写code以某种方式,这就是它?还是有其他的事情一样运行库支持,使这种情况发生?

Is this feature strictly a compiler feature then? does the compiler rewrite the code in some manner and that's it? or are there other things like runtime support that make this happen?

推荐答案

没有,不是的完全的编译器。它依赖于一些新的接口,如<一个href="http://msdn.microsoft.com/en-gb/library/system.runtime.compilerservices.inotifycompletion.aspx"><$c$c>INotifyCompletion有的框架的执行的支持,如<一个href="http://msdn.microsoft.com/en-gb/library/hh138506.aspx"><$c$c>AsyncTaskMethodBuilder.我不相信有,虽然所需要的任何CLR的变化。

No, it's not entirely in the compiler. It relies on some new interfaces such as INotifyCompletion and some framework implementation support such as AsyncTaskMethodBuilder. I don't believe there are any CLR changes required though.

编译器做了很多工作,构建国家机器 - 它只是指一些这些类型的状态机内。哦,还有很多工作 - 相关类型的人显著主要是出于性能方面的修改。

The compiler does a lot of work, building a state machine - it just refers to a few of those types within the state machine. Oh, and a lot of the Task-related types were significantly modified primarily for performance reasons.

我有一个一系列博客文章它最初写对CTP,但的只有的使用香草.NET 4和一些类我刮起了自己。他们不会对生产实施工作(如事情改变了一点随着时间的推移),但他们会给你这是怎么回事幕后一般IM pression。

I have a series of blog posts which were initially written against the CTP but only using vanilla .NET 4 and some classes I whipped up myself. They won't work against the production implementation (as things changed a bit over time) but they'll give you a general impression of what's going on behind the scenes.

这篇关于是在编译器严格执行新的C#异步功能的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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