WPF全局异常处理程序全局、异常、程序、WPF

2023-09-02 10:15:40 作者:树屿

有时候,在不可复制的情况下,没有任何消息,我的WPF应用程序崩溃。该应用程序只是瞬间关闭。

sometimes, under not reproducible circumstances, my WPF application crashes without any message. The application simply close instantly.

哪里是实施全球try / catch块的最佳场所。至少我要实现与一个消息:很抱歉给您带来不便......

Where is the best place to implement the global Try/Catch block. At least i have to implement a messagebox with: "Sorry for the inconvenience ..."

推荐答案

您可以处理AppDomain.UnhandledException事件

You can handle the AppDomain.UnhandledException event

编辑:实际上,这个事件可能是更充分的:Application.DispatcherUnhandledException

actually, this event is probably more adequate: Application.DispatcherUnhandledException