TPL (Task Parallel Library) multithreading, concurrency features

Source: Internet
Author: User

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

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.