Proper way to use Async with VS 2010 now that VS 2012 is released?
Asked Answered
B

3

11

Due to work restrictions, I need to continue using Visual Studio 2010 for the immediate future. At the same time, I have been learning about Async in my personal coding. Is the latest Async CTP fully consistent with the Async language features of C# 5.0? And is installing the Async CTP the correct way to use Async with VS2010?

Baseball answered 21/8, 2012 at 13:58 Comment(0)
Q
11

The Async CTP is the only way to use async in Visual Studio 2010. However, it is not the async that made it into .NET 4.5 / Visual Studio 2012, several bugs in the CTP have been fixed in the final release. You will not get these bug fixes in Visual Studio 2010, according to the CTP's readme:

NOTE ON "AS IS" LICENSE

While the Async CTP license does not prevent you using it at your own risk in production environments, we advise you not to. The goal of this CTP is solely to gather feedback on our intended async design. We did not design or build it to be used in production environments, and did not test it as thoroughly as is needed for use in production environments, and we believe it has too many flaws to be fit for use in production environments. We gratefully appreciate feedback on the Async CTP, but we do not plan to make any fixes to the Async CTP itself: the fixes we make will only appear in the eventual supported released product.

If you absolutely need VS 2010, what I would try is to install the Async CTP first, and then install .NET 4.5 (both runtime and SDK). Develop in Visual Studio, but build using the standalone compiler.

Quean answered 21/8, 2012 at 14:13 Comment(8)
Thank you kindly for the information and notice. Other than bugs, do you know if the Async 'API' is consistent between the two?Baseball
@ach Some parts that have been made part of .NET Framework 4.5 aren't part of .NET Framework 4, and are therefore made available as a separate DLL that you would need to distribute with your application. Some of the functions have also had name changes, probably most notably TaskEx.Run(...) (Async CTP) versus Task.Run(...) (.NET Framework 4.5).Quean
@hvd I don't understand , If i have 2010 and 4.5.1(!) installed , would I be able to use async await using this CTP ? ( without worries...?).Bondon
@RoyiNamir Sort of. Whether you've got 4.5 or 4.5.1 doesn't matter. If you use the Async CTP's compiler, you'll be using a buggy compiler, and I wouldn't trust its generated output regardless of which version of .NET you've got installed. The Async CTP can be useful for its IDE improvements (mainly to make the editor not detect async and await as a syntax error). .NET 4.5's standalone compiler is independent of the Async CTP compiler, and can be used to correctly compile your project, even if your project targets .NET 4.0. If you correctly combine the two, yes, you can use async/await.Quean
@hvd tnx , so the running(!) code would act the exact same ? ( i mean would the IL be the same ? - I don't care about compiler - compile time warnings)Bondon
@RoyiNamir No, the Async CTP's compiler generates broken code. That's not just bogus warnings, that's code that won't behave correctly at runtime. You need the standalone compiler.Quean
@hvd Ok. understood. thank you. ( how the hell would I convince my boss to advance to 2012 , if he doesn't know what are the benefit for async IO / asp.net.....at least i'm learning aside all the new stuff)Bondon
@RoyiNamir Well, for that, I suppose you could install the Express edition of VS2012/VS2013, use that to update one part of your project to use async, and show your boss the improvements. :)Quean
R
3

Given the way that .NET 4.5 installs on top of .NET 4, and the challenges that that could present, I would try to separate your work environment from your personal development environment as far as possible.

You could install VS2010 and VS2012 on the same machine, and I'd recommend that over using the async CTP:

  • Less pollution of your work IDE
  • Up-to-date version of C# 5
  • All the benefits of VS 2012 when you're using it

However, I think it would be safer to develop on a VM or a separate machine instead, if at all possible.

The least attractive option would be to use the CTP, IMO - I can see only risks on that front, to be honest.

Rabe answered 21/8, 2012 at 14:33 Comment(1)
Thank you kindly Jon for the information. My work and play environments are separate, I was hoping to be able to use the new features in my VS2010 work envionrment. But I think I will heed your advice and wait for a VS2012 install before using the Async features in production.Baseball
L
3

The Async CTPs are not fully consistent with the final C# 5.0 implementation, though the keywords are the same.

If your real business need is to produce an app that can run on .NET 4.0, then the recommended approach is to use VS2012 with the async targeting pack (available via NuGet).

Under this configuration, your development machine has .NET 4.5 and VS2012, however the binary produced from your solution build will be compatible with .NET 4.0.

This results in the fullest support for the async language feature, since the VS2012 + async targeting pack gives you the exact same official compiler, and is higher than CTP quality.

Leoleod answered 21/8, 2012 at 18:51 Comment(1)
This is great information! Thank you. The problem currently is that my company is slow to update development software so I am stuck using VS2010 for the time being.Baseball

© 2022 - 2024 — McMap. All rights reserved.