What is the difference between task and thread?

后端 未结 8 1589
庸人自扰
庸人自扰 2020-11-22 02:45

In C# 4.0, we have Task in the System.Threading.Tasks namespace. What is the true difference between Thread and Task. I did s

相关标签:
8条回答
  • 2020-11-22 03:32

    In addition to above points, it would be good to know that:

    1. A task is by default a background task. You cannot have a foreground task. On the other hand a thread can be background or foreground (Use IsBackground property to change the behavior).
    2. Tasks created in thread pool recycle the threads which helps save resources. So in most cases tasks should be your default choice.
    3. If the operations are quick, it is much better to use a task instead of thread. For long running operations, tasks do not provide much advantages over threads.
    0 讨论(0)
  • 2020-11-22 03:33

    Task is like a operation that you wanna perform , Thread helps to manage those operation through multiple process nodes. task is a lightweight option as Threading can lead to a complex code management
    I will suggest to read from MSDN(Best in world) always

    Task

    Thread

    0 讨论(0)
提交回复
热议问题