How to catch exceptions from a ThreadPool.QueueUserWorkItem?

后端 未结 6 1826
借酒劲吻你
借酒劲吻你 2020-12-01 07:19

I have the following code that throws an exception:

ThreadPool.QueueUserWorkItem(state => action());

When the action throws an exception

6条回答
  •  心在旅途
    2020-12-01 08:10

    If you have access to action's source code, insert a try/catch block in that method; otherwise, create a new tryAction method which wraps the call to action in a try/catch block.

提交回复
热议问题