我有一項任務的延續來處理錯誤:任務延續(OnlyOnFaulted)仍然得到未觀察到的異常
var uiScheduler = TaskScheduler.FromCurrentSynchronizationContext();
var loadTask = Task<List<OrderItemViewModel>>.Factory.StartNew(() =>
{
throw new Exception("derp");
});
var errorContinue = loadTask.ContinueWith(t =>
{
MainViewModel.RemoveViewModel(this);
}, CancellationToken.None, TaskContinuationOptions.OnlyOnFaulted, uiScheduler);
延續被擊中,但幾秒鐘後,我收到此錯誤中的應用:
通過等待任務 或訪問其Exception屬性未觀察到任務的例外情況。結果,終結者線程重新拋出了未觀測到的異常。
這與uiScheduler有關嗎?到類似的問題,解決的辦法是基本上我在做什麼A Task's exception(s) were not observed either by Waiting on the Task or accessing its Exception property. As a result, the unobserved exception was
由於寫了這個答案,微軟已經改變了.NET例外策略。請訪問https://msdn.microsoft.com/en-us/library/hh367887.aspx#core查看未查看的例外情況 –