The Task Parallel Library (TPL) is a set of public types and APIs in the System.Threading and System.Threading.Tasks names Paces. The purpose of the TPL is to do developers more productive by simplifying the process of adding parallelism and Concurre Ncy to applications.
The above is a description of the TPL library in MSDN. From the above description, the main purpose of TPL is to improve the efficiency of software developers by simplifying the processing of the parallel/concurrency-related logic of the application of moderate rain.
Here the main routines in the TPL library relate to the use of task and parallel.
1. Building a task array
New task[3];
2. Initialize array members (use factory here)
taskarray[0] = Task.Factory.StartNew (); taskarray[1] = Task.Factory.StartNew (); taskarray[2] = Task.Factory.StartNew ();
3. Using parallel to build processing logic
Parallel.For (05,
(i = Console.WriteLine (string. Format ("Print {0}.", i)));
4. Wait for all tasks to complete
Task.waitall (Taskarray);
TPL (Task Parallel Library) multithreading, concurrency features