Task-based Asynchronous Pattern (TAP)

The Task-based Asynchronous Pattern (TAP) is the newly provided asynchronous programming framework born in .NET 4. TAP provides features of APM and EAP with an added signaling lock like an API that offers a lot of interesting new features.

Task creation

In .NET, this asynchronous job takes the name of a task. A task is also a class of the System.Threading.Tasks namespace. Here is a basic example:

var task = Task.Run(() => { Thread.Sleep(3000); //returns a random integer return DateTime.Now.Millisecond; }); Console.Write("Starting data computation..."); //waiting the completation while (task.Status != TaskStatus.RanToCompletion) { Console.Write("."); Thread.Sleep(100); } Console.WriteLine(" OK"); Console.WriteLine("END"); ...

Get Learning .NET High-performance Programming now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.