Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Using async-await on .net 4

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

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

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

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.

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


If you are open to considering other .Net languages, F# can solve your problem. It has had the async{} computation expression for years, and is backwards compatible even with .Net 2.0. Minimum requirement is Windows XP SP3. The runtime can be downloaded here.


It's possible to use the VS 12 beta to target .NET 4.0 using async/await.

You need to copy some code into your project that provides the types that the compiler relies on.

Details here

Edit: we've taken this technique and turned it into a open source library called AsyncBridge: https://nuget.org/packages/AsyncBridge


If you want to be able to distribute your software, I think that the Mono solution is really your only option right now. You also say that you want the end result to run on Mono over Linux and OS X. Targeting Mono to begin with seems like the natural solution.

Your next issue is the IDE. MonoDevelop would obviously work well but you say you prefer Visual Studio.

Greg Hurlman created a profile to code against Mono 2.8 from Visual Studio. If you follow-up with him, he might be able to point you in the right direction for developing against Mono 2.11/2.12 in Visual Studio.

Of course, there is also Mono Tools for Visual Studio which is a commercial product. I assume that it is still being offered by Xamarin.

You might also be able to run the required 4.5 profile assemblies from Mono on top of .NET but I have not tried that. The 4.5 profile is a strict super-set of the 4.0 API. Perhaps give it a shot and report back.

EDIT: It looks like perhaps you can use the Visual Studio Async CTP in production now

Here is what it says on the download page:

Includes a new EULA for production use. Note - This license does not constitute encouragement for you to use the CTP for your production code. The CTP remains an unsupported and use-at-your-own-risk Technology Preview. However, we’ve received many requests from developers to use the CTP for production code, and so have changed the license to allow that.


If you want to start distributing your software after MS releases C# 5.0, then you can start developing using AsycnCTP. Otherwise I wouldn't recommend you to use it, as it is just CTP, not even a beta. It can be changed a lot close to the beta stage and to the release. It may be unstable, etc.

If you want to introduce easy async operations in your application I would recommend you to use Reactive Extensions and stuff built on top (Reactive UI, etc), it is just beautiul.

As for VS2012, it also contains the same Async CTP as far as I remember from my //Build/ tablet MS gave me on that conference.