Different between task and thread in .Net core
2 Answers
Know the answer? Post it. Somebody with the same question will find it here.
Know the answer? Post it. Somebody with the same question will find it here.
Answer a question in the forums and earn +20 SHARP for every answer.
See unanswered questions
DevSocialUpcoming · 3rd editionAI Agents ConferenceDec 1–3, 2026Live onlineFree to attend5days leftRegister
Rajanikant HawaldarRank #110 · 20.2K reputationPosted Oct 30, 2022, 10:31 AM EDT
Here are some differences between a task and a thread.
1) The Thread class is used for creating and manipulating a thread in Windows. 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.
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.
5) We can easily implement Asynchronous using ’async’ and ‘await’ keywords.
6) A new Thread()is not dealing with Thread pool thread, whereas Task does use thread pool thread.
7) A Task is a higher level concept than Thread.
Brahma Prakash ShuklaRank #633 · 3.8K reputationPosted Oct 30, 2022, 11:54 AM EDT
Thread
The bare metal thing, you probably don't need to use it, you probably can use a
LongRunningtask and take the benefits from the TPL - Task Parallel Library, included in .NET Framework 4 (february, 2002) and above (also .NET Core).Tasks
Abstraction above the Threads. It uses the thread pool (unless you specify the task as a
LongRunningoperation, if so, a new thread is created under the hood for you).