![]() Creating and running tasks explicitlyĪ task that doesn't return a value is represented by the class. The TPL might employ various optimizations, especially with large numbers of delegates.įor more information, see How to: Use Parallel.Invoke to Execute Parallel Operations.įor greater control over task execution or to return a value from the task, you must work with Task objects more explicitly. The number of Task instances that are created behind the scenes by Invoke isn't necessarily equal to the number of delegates that are provided. The first task is represented by a lambda expression that calls a method named DoSomeWork, and the second task is represented by a lambda expression that calls a method named DoSomeOtherWork. The following example shows a basic Invoke call that creates and starts two tasks that run concurrently. ![]() The lambda expression can either call a named method or provide the code inline. ![]() The easiest way to create these delegates is to use lambda expressions. Just pass in an Action delegate for each item of work. The Parallel.Invoke method provides a convenient way to run any number of arbitrary statements concurrently. Tasks and the framework built around them provide a rich set of APIs that support waiting, cancellation, continuations, robust exception handling, detailed status, custom scheduling, and more.įor both reasons, TPL is the preferred API for writing multi-threaded, asynchronous, and parallel code in. More programmatic control than is possible with a thread or work item. This process makes tasks relatively lightweight, and you can create many of them to enable fine-grained parallelism. These algorithms provide load balancing to maximize throughput. More efficient and more scalable use of system resources.īehind the scenes, tasks are queued to the ThreadPool, which has been enhanced with algorithms that determine and adjust to the number of threads. The term task parallelism refers to one or more independent tasks running concurrently. In some ways, a task resembles a thread or ThreadPool work item but at a higher level of abstraction. ![]() The Task Parallel Library (TPL) is based on the concept of a task, which represents an asynchronous operation. ![]()
0 Comments
Leave a Reply. |
AuthorWrite something about yourself. No need to be fancy, just an overview. ArchivesCategories |