views:

798

answers:

2

As some may have seen in .NET 4.0, they've added a new namespace System.Threading.Tasks which basically is what is means, a task. I've only been using it for a few days, from using ThreadPool.

Which one is more efficient and less resource consuming? (Or just better overall?)

+4  A: 

The objective of the Tasks namespace is to provide a pluggable architecture to make multi-tasking applications easier to write and more flexible.

The implementation uses a TaskScheduler object to control the handling of tasks. This has virtual methods that you can override to create your own task handling. Methods include for instance

protected virtual void QueueTask(Task task)
public virtual int MaximumConcurrencyLevel

There will be a tiny overhead to using the default implementation as there's a wrapper around the .NET threads implementation, but I'd not expect it to be huge.

There is a (draft) implementation of a custom TaskScheduler that implements multiple tasks on a single thread here.

Jeremy McGee
All very true but I don't think the main purpose or attraction of the Task class is the custom scheduler. That is a very specialized feature that will be invaluable in some cases but most users will never touch it.
Henk Holterman
A: 

Another good point to consider about task is, when you use ThreadPool, you don't have any way to abort or wait on the running threads (unless you do it manually in the method of thread), but using task it is possible. Please correct me if I'm wrong

lakhlaniprashant.blogspot.com