A task is an abstraction of a higher level than a thread or ThreadPool. Essentially, you install a function in a task and request that the runtime execute it as best as possible. You can have many dozens, if not hundrends of Tasks, which will be performed by a limited number of threads.
Using tasks, the developer creates as many tasks as necessary, combine them to create threads (workflows in F #) and control their cancellation without worrying about how the threads are distributed or used. It depends on the runtime to choose the best way to complete all tasks with a limited number of threads.
Tasks greatly simplify the implementation of parallel programming patterns. The ParallelExtensionExtras library provides methods for converting Begin / EndXXX pairs to tasks that can be bound, and a preliminary version of the task Iteration iteration, which is used by Async CTP to provide async / wait syntax. You can use the ConcurrentCollection of tasks to create a task queue, similar to the AsyncCall example in ParallelExtensionExtras, or go even further and create agents similar to Scala, Erlang or F #. Async CTP's DataFlow is another example of what you can create with tasks.
You should remember that although a typical laptop has 2 cores and a typical desktop has 4, small servers already have 8 or more cores, and soon they will have many more. Keeping all of these key manual workers by scheduling flows AND avoiding blocking can be a major headache.
source share