ここでタスクを開始します。
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!");)
、スレッドは壊れません。なんで?