在 .net 4 上使用异步等待 [英] Using async-await on .net 4

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

问题描述

我目前正在开始创建一个应用程序,该应用程序将从 C# 5 的 async-await 特性中获益良多.但我不确定要使用哪个版本的 VS 和异步运行时.

I'm currently starting to create an application that would profit a lot from C# 5's async-await feature. But I'm not sure which version of VS and of the async runtime to use.

查看操作系统流行度图表,我需要再支持 Windows XP 三年左右.看起来 .net 4.5 只能在较新版本的 Windows 上运行,所以我需要针对 .net 4.0.开发机器使用的是Windows 7,所以使用较新版本的VS是没有问题的.

Looking at OS popularity charts, I'll need to support Windows XP for another three years or so. It looks like .net 4.5 runs only on newer versions of Windows, so I need to target .net 4.0. The development machines use Windows 7, so using a newer version of VS is not a problem.

现在我需要首先选择一个编译器来执行此操作:

  • 带有 AsyncCTP 的 VS2010
  • VS2012 预览版(以及发布后的最终版),将目标设置为 .net 4.0
  • Mono(看起来 2.12 有 async-await,我更喜欢/习惯使用 VS 而不是 MonoDevelop 作为 IDE)

哪个代码生成错误较少?看着 Jon Skeet 的博客 VS2012 预览版使用的代码生成器从未使用过 CTP.

Which one has fewer code-gen bugs? Looking at Jon Skeet's blog the VS2012 Preview uses a never code-generator than the CTP.

更重要的是使用哪个运行时?

VS2012 是否包含用于 .net 4 的可再分发异步运行时?

Does VS2012 contain a redistributable async runtime for use with .net 4?

通过引用 AsyncCTP 运行时,我设法通过预览编译了代码.但由于 CTP 有奇怪的许可条件,这看起来不是一个好的长期解决方案.

I managed to compile code, with the preview, by referencing the AsyncCTP runtime. But since the CTP has strange licensing conditions, that doesn't look like a good long term solution.

还是应该使用第三方实现?也许单声道有一个?

Or should I use a third party implementation? Perhaps mono has one?

为了分发库,我更喜欢简单地将 dll 放在与应用程序相同的目录中,而不是某种安装程序.

For distributing the library I prefer simply putting the dll in the same directory as the application, instead of some kind of installer.

如果我的二进制文件无需更改就可以在 mono+Linux/MacOS 上运行,我也很喜欢.因此,运行时应该与内置的任何单声道(可能是 2.12)兼容,或者允许在非 Windows 操作系统上使用.

I'd also like it if my binaries would work without changes on mono+Linux/MacOS. So the runtime should either be compatible with whatever mono (2.12 probably) has built in, or allow use on non windows OSs.

推荐答案

Microsoft 发布了 Async Targeting Pack (Microsoft.Bcl.Async) 通过 Nuget 作为 AsyncCTP 的替代品.

Microsoft released the Async Targeting Pack (Microsoft.Bcl.Async) through Nuget as a replacement for the AsyncCTP.

您可以在此处阅读更多相关信息:http://blogs.msdn.com/b/bclteam/archive/2013/04/17/microsoft-bcl-async-is-now-stable.aspx.

You can read more about it here: http://blogs.msdn.com/b/bclteam/archive/2013/04/17/microsoft-bcl-async-is-now-stable.aspx.

您可以在此处阅读有关先前版本的信息:http://blogs.msdn.com/b/lucian/archive/2012/04/24/async-targeting-pack.aspx.

You can read about the previous version here: http://blogs.msdn.com/b/lucian/archive/2012/04/24/async-targeting-pack.aspx.

由于此包得到官方支持,我现在相信针对 XP + async 的最佳选择是使用 Visual Studio 2012 + C#5 + Async Targeting Pack.

As this pack is officially supported, I now believe the best option for targeting XP + async would be using Visual Studio 2012 + C#5 + Async Targeting Pack.

如果您觉得需要面向 .NET 3.5,您仍然可以使用(我的)AsyncBridge for .NET 3.5.

If you feel the need to target .NET 3.5 though, you can still use (my) AsyncBridge for .NET 3.5.

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

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