在这里我开始一个任务:
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!");)
则线程不会中断。为什么?