Condividi tramite


ParallelExtensionsExtras Tour #16 – Asynchronous Tasks for WebClient, SmtpClient, and Ping

Parallel

NET 4.0 includes significant advancements for developers writing parallel and concurrent applications, including Parallel LINQ (PLINQ), the Task Parallel Library (TPL), new thread-safe collections, and a variety of new coordination and synchronization data structures.

In this installment of the ParallelExtensionsExtras Tour, the author takes a look at how the Task Parallel Library isn’t just about CPU-bound operations.  The Task class is a great representation for any asynchronous operation, even those implemented purely as asynchronous I/O.

Task’s ability to represent arbitrary asynchronous operations without tying up threads is rooted in the TaskCompletionSource<TResult> class, and this becomes a building block for creating an unlimited number of higher-level asynchronous operations represented as a Task. 

With a method like this, you can very easily download a single file, but you can now also take advantage of the power of the Task class to, for example, download multiple files and perform a follow-up operation asynchronously only when all of the asynchronous downloads have completed, in this case outputting some diagnostic information about each download’s success or failure, e.g.

Check-out Tour #16 – to learn more about Asynchronous Tasks for WebClient, SmtpClient, and Ping: http://blogs.msdn.com/pfxteam/archive/2010/05/04/10007557.aspx

Technorati Tags: NET 4.0 Parallel

 

Shout it