[英]Exception from thread doesn't bubble up to main thread
在這里,我開始一個任務:
System.Threading.Tasks.Task.Factory.StartNew( () =>
RefreshCache(crmClientInfo)).ContinueWith(
previous => RefreshCacheExceptionHandling(previous.Exception),
TaskContinuationOptions.OnlyOnFaulted
);
...這是我的工人:
public void RefreshCache(CrmClientInfo _crmClientInfo)
{
AsyncManager.OutstandingOperations.Increment();
Timer timer = new Timer(10000);
timer.Elapsed += delegate
{
throw new AggregateException("Timeout!");
};
timer.Start();
OtherServices.RefreshCache(crmClientInfo);
AsyncManager.OutstandingOperations.Decrement();
}
如果異常不在計時器定義中而是在其他地方發生,則該異常正確地冒泡到RefreshCacheExceptionHandling()
。 但是,如果從計時器(AgregateException("Timeout!");)
則線程不會中斷。 為什么?
System.Threading.Timer類在ThreadPool線程上進行回調,並且完全不使用事件模型。
在以下位置查看文檔: http : //msdn.microsoft.com/zh-cn/library/zdzx8wx8.aspx
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.