Task.Run vs ThreadPool.QueueUserWorkItem

前端 未结 2 1174
时光说笑
时光说笑 2021-02-01 14:40

Not a subject expert I\'m trying to understand more of the async world available in .NET. Task.Run and ThreadPool.QueueUserWorkItem both allow dispatching work on a pool thread

2条回答
  •  南旧
    南旧 (楼主)
    2021-02-01 15:35

    One difference between ThreadPool.QueueUserWorkItem and Task.Run I recently realized is the way they handle exceptions.

    If an unhanded exception occurs inside ThreadPool.QueueUserWorkItem and not handled by global exception handler, it will crash parent thread. On the other hand, unhanded exceptions from Task.Run thread will not get propagated until you await or Task.Wait.

提交回复
热议问题