Search code examples
c#async-awaitasync-ctp

c# 4.0, async CTP and async C# 5.0 are compatible?


I have an application that use async CTP library to be able to use async/await keywords, and I know that the actual version of C#, 5.0, has this feature by default, and it is not all the exact version that async CTP. I mean that for example in async CTP exist TaskEx and in C# 5.0 not exists, is Task.

But dispite of these diferences, I would like to know if the Task object that is returned by the async methods are the same or not.

In my case, I have an Interface for a repository to access to the data base. This repository by the moment is implemented by a class that use C# 4.0, but it can use asyc CTP to return a Task and use the await keyowrd. But in the future, I would like to use other classes that use C# 5.0.

If my interace define a method that returns a Task, can I implement this inteface with the class that use C# 4.0 and the class that use C# 5.0? Or exists diference in the Task object in async CTP and C# 5.0?

PD: I correct the version of C#, I mean 5,0 instead of C# 4.5.

PD2: it seems that with VS2012 I can use Microsoft.Bcl.Async and Microsoft.CompilerServices.AsyncTargetingPack to use the asyn/await keywords in project which target is .NET 4.0. But I don't know which is the difference between them.


Solution

  • It's the same Task type that is returned. This type was introduced in .NET 4.0 as part of the Task Parallel Library.

    However, I would upgrade everything to VS2012 if I were you, replacing the Async CTP with Microsoft.Bcl.Async. The underlying compiler types are different (and mutually incompatible), and there are known bugs in the Async CTP as well as installation issues.