O'Reilly logo

Learning .NET High-performance Programming by Antonio Esposito

Stay ahead with the world's most comprehensive technology and business learning platform.

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, tutorials, and more.

Start Free Trial

No credit card required

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"); ...

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, interactive tutorials, and more.

Start Free Trial

No credit card required