How to catch exceptions from a ThreadPool.QueueUserWorkItem?

后端 未结 6 1825
借酒劲吻你
借酒劲吻你 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 07:50

    What I usually do is to create a big try ... catch block inside the action() method then store the exception as a private variable then handle it inside the main thread

提交回复
热议问题