Task and exception silence

前端 未结 4 635
暗喜
暗喜 2021-02-04 04:04

Why exceptions thrown within a task are silent exception and you never know if a certain exception has been thrown

try
{

 Task task = new Task(
  () => {
            


        
4条回答
  •  [愿得一人]
    2021-02-04 04:27

    No, tasks are not threads. Tasks represent a high level abstraction - they are a unit of work that is inherently parallelisable. Threads run units of work.

    In your first example, you create a unit of work and then tell it to run itself (how it does so is an implementation detail of Task). Whereas in your second example you explicitly schedule a unit of work (it would appear in a different manner to the implementation of Task).

提交回复
热议问题