Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

TPL vs Async in .net?

i didnt use TPL that much in .net 4 but i know its great for multi-core Applications

but in PDC i saw them announcing Async CTP & i only saw Async in F#

my Question is what is the difference between them & what are the best practices for each of them

thanks in advance

like image 731
Saif al Harthi Avatar asked Dec 16 '10 20:12

Saif al Harthi


People also ask

Is async await part of TPL?

Await & Async was built on the Task Parallel Library (TPL) which was introduced in the . NET Framework 4. Their purpose is to enable asynchronous programming.

What is TPL in the net?

The Task Parallel Library (TPL) is a set of public types and APIs in the System. Threading and System. Threading. Tasks namespaces. The purpose of the TPL is to make developers more productive by simplifying the process of adding parallelism and concurrency to applications.

How are threads different from TPL?

Compared to the classic threading model in . NET, Task Parallel Library minimizes the complexity of using threads and provides an abstraction through a set of APIs that help developers focus more on the application program instead of focusing on how the threads will be provisioned.

What is async in dotnet?

Using asynchronous programming indicates that a method can execute without waiting for another method to complete. Using async and await, we can run the methods above parallelly. Example 2: C#


1 Answers

The async features in C# 5 will use the TPL... which is just a library, of course. Asynchronous methods will simply make it a lot easier to use the TPL... given appropriate relatively-low-level async operations (e.g. "fetch a web page asynchronously" or "read a block of data asynchronously" it will be fairly easy to build higher-level asynchronous operations.

In terms of best practices - for TAP (Task-based Asynchronous Pattern) there's an interesting white paper. For parallel programming in general with .NET, there's a book by the Patterns and Practices group, "Parallel Programming with Microsoft .NET" and also Joe Duffy's book "Concurrent Programming on Windows" - although the latter predates the TPL slightly.

like image 189
Jon Skeet Avatar answered Dec 11 '22 05:12

Jon Skeet