Posts

Showing posts from August, 2014

From AsyncCompleted to async await

Since we got the magic of async/await on C# things got much easier on the developer front. Working with Tasks is the key to it, but we also have two older approaches in .NET framework that we need to deal with.  APM (Asynchronous Programming Model) The pair of Being / End methods.  EAP (Event-based Asynchronous Programming) The Method Async / Method Completed pair. Converting from APM to Tasks is achieved by means of the   System.Threading.Tasks.TaskFactory   class and its generic counterpart. Now converting from EAP to Tasks  requires us to use the TaskCompletionSource<T> class and notify of the state of the task as it goes. See the example of a "handshake" operation in a WCF service. I am also using the approach from my older post regarding events and anonymous methods. The return type of the WCF operation is WrappedResultOfString , and that will be the actual generic parameter of the Task<T> that the HandshakeAsync method will produ...