Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

when to use Task and when to use Thread?

Tags:

c#

I've just asked question about Task but realized that I actually want to ask more general question. Could someone summarize pros and cons of Tasks and Threads. How to understand should I use Task or Thread?

like image 311
Oleg Vazhnev Avatar asked Mar 15 '12 20:03

Oleg Vazhnev


1 Answers

Task is an order to program to do something in asynchronous way. The Thread is actually OS kernel object which executes what was requested. Think about Task like a clever thread aggregator/organizer that "knows" how much task is better to run contemporary on your CPU. It's just cleverer then common implementations of multi-threading (that's why it's suggested choice from Microsoft). It's a feature that helps you managing Threads in easier way.

Look also on this Should i use ThreadPools or Task Parallel Library for IO-bound operations that may give you some hints on performance issues you may be interested in.

like image 170
Tigran Avatar answered Oct 24 '22 04:10

Tigran