내 App.xaml.cs에서 DispatcherUnhandledExceptions (UI 스레드) 및 UnhandledException (UI가 아닌 스레드)을 처리하는 이벤트가 있습니다. Dispatcher 내부에서 예외를 throw하면 DispatcherHandler가 예외를 catch하고 처리합니다. 예외를 로깅 한 후 e.Handled를 true로 설정합니다. 지금 이상한 행동, dispatcher 외부 예외를 던지면. regualr statment, 컨트롤이 발송자 예외 처리기로 보내집니다 있지만 메서드를 처리 한 후에 기본적으로 컨트롤을 잃을하지만 여전히 찾고 실행하여 말할 수 있습니다. 대처리 후 알 수 없음/잠긴 상태로 입력됩니다. UnhandledException
대 중지 버튼에서 하나 더 설정하면 e.handled를 false로 설정하면 비 -ui 스레드 예외 처리기로 제어가 전송됩니다.
그렇다면 왜 내가 디스패처 처리기에서 예외를 처리 한 후 응용 프로그램을 잠글 수 있습니까?
여기
private void App_DispatcherUnhandledException(object sender, DispatcherUnhandledExceptionEventArgs e)
{
// log exception here
e.Handled = true;
} // control is lost after executing this block
private void App_UnhandledException(object sender, UnhandledExceptionEventArgs e)
{
try
{
Exception ex = e.ExceptionObject as Exception;
// log exception here
}
finally
{
Environment.Exit(-1);
}
}
e.handled = true를 실행 한 후 앱이 야채 상태로 들어가는 이유는 무엇입니까? 내 창 생성자에서, 나는 예외를 throw하고, 새로운 Exception ("약간의 예외")을 던집니다. 컨트롤은 dispatcherUnhandledException 핸들러로 보내지 만 앱은 계속 실행됩니다. – Syler
창 생성자에서 예외를 throw하지 않는 것이 좋습니다. 대신 논리를 Initialized 또는 Loaded 이벤트에 넣은 다음 자신을 창으로 죽이십시오. –