How can I detect a ThreadAbortException in a finally block? (.NET)

前端 未结 7 2183
太阳男子
太阳男子 2020-12-15 12:08

I have some critical logic in a finally block (with an empty try block), because I want to guarantee that the code gets executed even if the thread is aborted. However, I\'d

7条回答
  •  甜味超标
    2020-12-15 12:23

    You can actually execute code in the catch statement just fine for a ThreadAbortException. The problem is that the exception will be rethrown once execution leaves the catch block.

    If you want to actually stop the exception from continuing you can call Thread.ResetAbort(). This does require full trust though and unless you have a specific scenario, it's almost certainly the wrong thing to do.

    ThreadAbortException

提交回复
热议问题