Free cookie consent management tool by TermsFeed Policy Generator

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

#2258: added StartAsync to IExecutable

File:
1 edited

Legend:

Unmodified
Added
Removed
  • branches/Async/HeuristicLab.DebugEngine/3.3/DebugEngine.cs

    r12012 r13349  
    174174    }
    175175
    176     public override void Start() {
    177       base.Start();
     176    public override async Task StartAsync(CancellationToken cancellationToken) {
     177      await base.StartAsync(cancellationToken);
    178178      cancellationTokenSource = new CancellationTokenSource();
    179179      stopPending = false;
    180       Task task = Task.Factory.StartNew(Run, cancellationTokenSource.Token, cancellationTokenSource.Token);
    181       task.ContinueWith(t => {
    182         try {
    183           t.Wait();
    184         }
    185         catch (AggregateException ex) {
     180      using (var cts = CancellationTokenSource.CreateLinkedTokenSource(cancellationTokenSource.Token, cancellationToken)) {
     181        Task task = Task.Factory.StartNew(Run, cts.Token, cts.Token);
     182        await task.ContinueWith(t => {
    186183          try {
    187             ex.Flatten().Handle(x => x is OperationCanceledException);
     184            t.Wait();
    188185          }
    189           catch (AggregateException remaining) {
    190             if (remaining.InnerExceptions.Count == 1) OnExceptionOccurred(remaining.InnerExceptions[0]);
    191             else OnExceptionOccurred(remaining);
     186          catch (AggregateException ex) {
     187            try {
     188              ex.Flatten().Handle(x => x is OperationCanceledException);
     189            }
     190            catch (AggregateException remaining) {
     191              if (remaining.InnerExceptions.Count == 1) OnExceptionOccurred(remaining.InnerExceptions[0]);
     192              else OnExceptionOccurred(remaining);
     193            }
    192194          }
    193         }
    194         cancellationTokenSource.Dispose();
    195         cancellationTokenSource = null;
    196 
    197         if (stopPending) ExecutionStack.Clear();
    198         if (stopPending || !CanContinue) OnStopped();
    199         else OnPaused();
    200       });
     195          cancellationTokenSource.Dispose();
     196          cancellationTokenSource = null;
     197
     198          if (stopPending) ExecutionStack.Clear();
     199          if (stopPending || !CanContinue) OnStopped();
     200          else OnPaused();
     201        });
     202      }
    201203    }
    202204
Note: See TracChangeset for help on using the changeset viewer.