Click here to Skip to main content
15,886,833 members
Please Sign up or sign in to vote.
1.00/5 (1 vote)
See more:
Hi All,

I am wondering which class in .Net is better for parallel programming...Thread or Task
which one to prefer - when and why ?
Please answer in simple words, as i am new to Parallel programming.

Thanks:)
Posted
Updated 14-Feb-15 11:00am
v2
Comments
PIEBALDconsult 14-Feb-15 17:48pm    
I'm old-school, I use Threads.
[no name] 14-Feb-15 19:26pm    
Thanks, i read about tasks also - Could you explain why Threads over task
Sergey Alexandrovich Kryukov 14-Feb-15 21:03pm    
The whole approach is wrong. Threads certainly needed, but there are cases when Tasks have apparent benefits. Tasks are also based on threads, but threads are abstracted out. You can use threads instead of Tasks, but threading detail could be unnecessary detail. But there is a number of sure cases when Tasks are unsuitable. This topic is too big. I suggest you learn both, perhaps starting from threads...
—SA
Kuthuparakkal 15-Feb-15 10:17am    
Depends!

1 solution

There is no such thing as "best" - only "most appropriate".

You haven't given much detail but for your case I would say Task is easier for the beginner. In any case I'd suggest a book as this is a difficult subject.

Also - I'd suggest you make some additional constraints to your code before you add parallelism - like immutable classes .. this will save you gray hairs later.
 
Share this answer
 
Comments
Valery Possoz 14-Feb-15 18:55pm    
Agree! It depends what you need to do. Another option for a beginner is to use a BackgroundWorker as it is so simple to use.
[no name] 14-Feb-15 19:23pm    
I need to make a scheduler that send Emails to users per day..
Actually i am new to Task and TPL (task parallel library) but having knowledge of Threads.
I am confused why Task is easier for beginners ? Could you explain please
Duncan Edwards Jones 16-Feb-15 8:38am    
Basically (very simplified explanation) the Task syntax explains what you want the program to do whereas the Thread syntax explains how you want it to do it...and also the async/await keywords are part of that.
[no name] 18-Feb-15 12:18pm    
Thanks Duncan Edwards Jones, that's was very clear and concise.
Thanks :)
- Finally i did it using 8 threads on a quad core proc

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900