Dispatcher.UnhandledException 事件


在通过 InvokeBeginInvoke 执行委托的过程中,如果引发线程异常且未能捕获该异常,则发生此事件。Occurs when a thread exception is thrown and uncaught during execution of a delegate by way of Invoke or BeginInvoke.

 event System::Windows::Threading::DispatcherUnhandledExceptionEventHandler ^ UnhandledException;
public event System.Windows.Threading.DispatcherUnhandledExceptionEventHandler UnhandledException;
member this.UnhandledException : System.Windows.Threading.DispatcherUnhandledExceptionEventHandler 
Public Event UnhandledException As DispatcherUnhandledExceptionEventHandler 


如果 InvokeBeginInvoke 未捕获到委托执行期间引发的异常,则会引发此事件。This event is raised when an exception that was thrown during execution of a delegate by way of Invoke or BeginInvoke is uncaught.

处理程序可以将异常标记为已处理,这将阻止调用内部异常处理程序。A handler can mark the exception as handled, which will prevent the internal exception handler from being called.

必须谨慎编写此事件的事件处理程序,以避免创建辅助异常并捕获发生的任何异常。Event handlers for this event must be written with care to avoid creating secondary exceptions and to catch any that occur. 建议避免在处理程序中分配内存或执行任何资源密集型操作。It is recommended to avoid allocating memory or doing any resource intensive operations in the handler.

UnhandledExceptionFilter 事件提供了不引发 UnhandledException 事件的方法。The UnhandledExceptionFilter event provides a means to not raise the UnhandledException event. 首先引发 UnhandledExceptionFilter 事件,如果 DispatcherUnhandledExceptionFilterEventArgs 上的 RequestCatch 设置为 false,则不会引发 UnhandledException 事件。The UnhandledExceptionFilter event is raised first, and If RequestCatch on the DispatcherUnhandledExceptionFilterEventArgs is set to false, the UnhandledException event will not be raised.