Ignore:
Timestamp:
11/23/15 21:18:26 (3 years ago)
Author:
jkarder
Message:

#2258: added StartAsync to IExecutable

File:
1 edited

Legend:

Unmodified
Added
Removed
  • branches/Async/HeuristicLab.Algorithms.DataAnalysis/3.4/FixedDataAnalysisAlgorithm.cs

    r12012 r13349  
    7070    }
    7171
    72     public override void Start() {
    73       base.Start();
     72    public override async Task StartAsync(CancellationToken cancellationToken) {
     73      await base.StartAsync(cancellationToken);
    7474      var cancellationTokenSource = new CancellationTokenSource();
    7575
    7676      OnStarted();
    77       Task task = Task.Factory.StartNew(Run, cancellationTokenSource.Token, cancellationTokenSource.Token);
    78       task.ContinueWith(t => {
    79         try {
    80           t.Wait();
    81         }
    82         catch (AggregateException ex) {
     77      using (var cts = CancellationTokenSource.CreateLinkedTokenSource(cancellationTokenSource.Token, cancellationToken)) {
     78        Task task = Task.Factory.StartNew(Run, cts.Token, cts.Token);
     79        await task.ContinueWith(t => {
    8380          try {
    84             ex.Flatten().Handle(x => x is OperationCanceledException);
     81            t.Wait();
    8582          }
    86           catch (AggregateException remaining) {
    87             if (remaining.InnerExceptions.Count == 1) OnExceptionOccurred(remaining.InnerExceptions[0]);
    88             else OnExceptionOccurred(remaining);
     83          catch (AggregateException ex) {
     84            try {
     85              ex.Flatten().Handle(x => x is OperationCanceledException);
     86            }
     87            catch (AggregateException remaining) {
     88              if (remaining.InnerExceptions.Count == 1) OnExceptionOccurred(remaining.InnerExceptions[0]);
     89              else OnExceptionOccurred(remaining);
     90            }
    8991          }
    90         }
    91         cancellationTokenSource.Dispose();
    92         cancellationTokenSource = null;
    93         OnStopped();
    94       });
     92          cancellationTokenSource.Dispose();
     93          cancellationTokenSource = null;
     94          OnStopped();
     95        });
     96      }
    9597    }
    9698    private void Run(object state) {
Note: See TracChangeset for help on using the changeset viewer.