Differences Between Task And Thread
A Task represents some asynchronous operation and is part of the Task Parallel Library, a set of APIs for running tasks asynchronously and in parallel. The task can return a result.
- In .NET, threads and tasks are two different ways for doing multi-threading.
- Thread is a general programming concept. On the other hand, Microsoft created Task in .NET to simplify the used of Threads.
- Tasks are like a wrapper over Threads.
- Tasks internally uses threads only.
What are the advantages of Tasks over Threads?
Advantages of Tasks over Threads:
- Simplified Code.
- Exception handling.
- A Task can return a result, but there is no proper way to return a result from Thread.
- We can apply chaining and parent/ child on multiple tasks, but it can be very difficult in threads.