2

ここでタスクを開始します。

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!");)、スレッドは壊れません。なんで?

4

1 に答える 1

1

System.Threading.Timer クラスは、ThreadPool スレッドでコールバックを作成し、イベント モデルをまったく使用しません。

こちらのドキュメントをご覧ください: http://msdn.microsoft.com/en-us/library/zdzx8wx8.aspx

于 2013-02-21T12:16:03.543 に答える