Interview Question
Qus: Differentiate between Task and Thread in .NET.
1) Task is more abstract then threads. It is always advised to use tasks instead of thread as it is created on the thread pool which has already system created threads to improve the performance.
2) The task can return a result. There is no direct mechanism to return the result from a thread.
3) Task supports cancellation through the use of cancellation tokens. But Thread doesn't.
4) A task can have multiple processes happening at the same time. Threads can only have one task running at a time.
Answers (2)
2) The task can return a result. There is no direct mechanism to return the result from a thread.
3) Task supports cancellation through the use of cancellation tokens. But Thread doesn't.
4) A task can have multiple processes happening at the same time. Threads can only have one task running at a time.