귀하의 질문은 매우 모호하지만 최근에 직면 한 문제처럼 보입니다. 몇 가지 이유로, 내가 작업자 스레드에서 예외를 잡았을 때 그것을 UI 스레드에 다시 던지려고했는데 예외가 처리되지 않았습니다 (하위 수준이벤트 하위 수준 오류 관리에도 불구하고) 및 응용 프로그램이 충돌했습니다. 여기
나를
DispatcherPriority.SystemIdle
에 대한 낮은 우선 순위에 디스패처 우선 순위를 변경 내 원래의 코드
try
{
action(); // Perform task from worker thread
}
catch (Exception ex)
{
var stackBeforDispatch = ex.StackTrace;//get the stack trace before it is dispatched to keep track of the original error origin
var uiThread = Application.Current != null ? Application.Current.Dispatcher : Dispatcher.CurrentDispatcher;//try to find the ui dispatcher if any
Action action1 = action;
//dispatch to ui thread so that the information goes up to the user
uiThread.Invoke(new Action(() =>
{
ex.Source = ex.Source += string.Format("{0}From Thread: {0} {1}{0}From Method: {0} {2}{0}Stack trace before Dispatch: {0} {3}",
Environment.NewLine,
_dispatcherThread.Name,
action1.Method.Name,
stackBeforDispatch);
throw ex;
}));
}
이며, 문제를 해결하는 것 : 지금, 백그라운드 스레드에서 발생하는 모든 내 예외가 제대로되어 던져 다시 DispatcherUnhandledException
에 의해 처리되는 UI 스레드에 전달됩니다.
는 사실, 난 왜 이해 '해달라고, 나는 당신의 질문이 그에게 설명 검색 : 답변의
아무도 지금까지 맞는 것 같다 찾을 수 없습니다. 질문을 명확히 할 수 있습니까? '때로는 예외를 throw하지 않습니다.'또는 '항상 예외를 throw하지만 때때로 UI가 아닌 스레드에서 발생하는 경우'를 의미합니까? – Kimberly