Can I prevent an uncaught exception in another AppDomain from shutting down the application?

后端 未结 2 1585
感动是毒
感动是毒 2020-12-20 16:29

I\'m having trouble with a misbehaved library that throws an exception in a finalizer, which of course crashes the application.

To avoid this, I tried loading the li

相关标签:
2条回答
  • 2020-12-20 17:13

    Actually, back in .NET 1.0/1.1, it behaved as you need. You can still revert to this behavior by simply adding this row to your application configuration file, inside the "runtime" node:

    <runtime>
        <legacyUnhandledExceptionPolicy enabled="1"/>
    </runtime>
    

    This will prevent an unhandled exception in a different thread from terminating the entire process.

    0 讨论(0)
  • 2020-12-20 17:22

    An AppDomain is nice since you can ditch the program state but you still have the problem that the thread is dead. That this happens on the finalizer thread is fatal, the CLR will abort the process without recourse.

    The only 'fix' is to run this component in its own process. You can shoot it in the head with Process.Kill() to prevent the finalizer thread from running at process exit. Use one of the interprocess communication mechanisms that .NET supports to talk to it. A socket, named pipe, Remoting or WCF. Good luck with it.

    0 讨论(0)
提交回复
热议问题