Task Parallel library:1 of N
Http://www.codeproject.com/Articles/152765/Task-Parallel-Library-of-n
What is the correlation between Task and thread, lambda, action,funct.
Task provides more convenience than thread.
Thread
1. Create fee time, consume memory and CPU resources
For example, when a new was Thread
started in. NET, there was a whole process that goes with that, such as creating queues, T Hread Local storage, managing the Thread
' s lifecycle etc. This takes time
ThreadPool
1. ThreadPool eliminates the time to create thread, and the user directly delegates the work item to ThreadPool to schedule its internal thread invocation.
2. But classic threading ThreadPool
, when a work item is already in the execution, the user can not go directly to shut down, want the result is also very direct.
However, even using the classic threading ThreadPool
, there were problems in so you could don't cancel a work item once it had Been queued ThreadPool
with the, or get a return to result that easily. It just doesn ' t read that well either. There is a excellent article here on CodeProject this tackles some of these issues:smart ThreadPool, which is pretty exc Ellent actually. However, the new TPL infrastructure have got all these problems covered, and many many more useful features in my opinion.
Task
1. The new TPL infrastructure have got all these problems covered, and many many more useful features in my opinion
The Task inherits the advantages of ThreadPool and solves the ThreadPool problem. The essence can also be said smart ThreadPool
2. A TPL Task
actually uses the ThreadPool
internally.
Task, ThreadPool, Thread, Scheduler
It is worth mentioning that Task
S was merely wrappers for passing a delegate of work to being done, also storing state, exce Ptions, and continuations amongst others. That work could or May is not being done by the ThreadPool, and as already stated, which would depend upon the scheduler used.
Common usage scenarios
Task
s also seem to is more inline with how people think about things. For instance, imagine this scenario: "I want to call a Web Service and has it return a List<int>
". Using a TPL Task
, I would create a and Task<List<int>>
get it to call some service on its payload delegate (which would use the ) that returned me a List<int>
.
Task and UI Thread
C # Task