Free cookie consent management tool by TermsFeed Policy Generator

Ignore:
Timestamp:
07/28/17 16:47:42 (7 years ago)
Author:
jkarder
Message:

#2258: merged r15287 into stable

Location:
stable
Files:
2 edited

Legend:

Unmodified
Added
Removed
  • stable

  • stable/HeuristicLab.DebugEngine/3.3/DebugEngine.cs

    r14186 r15292  
    2323using System.Linq;
    2424using System.Threading;
    25 using System.Threading.Tasks;
    2625using HeuristicLab.Common;
    2726using HeuristicLab.Core;
     
    161160        while (skipStackOperations && !(CurrentOperation is IAtomicOperation) && CanContinue)
    162161          ProcessNextOperation(true, cancellationTokenSource.Token);
    163       }
    164       catch (Exception ex) {
     162      } catch (Exception ex) {
    165163        OnExceptionOccurred(ex);
    166164      }
     
    174172    }
    175173
    176     public override void Start() {
    177       base.Start();
    178       cancellationTokenSource = new CancellationTokenSource();
     174    public override void Start(CancellationToken cancellationToken) {
     175      base.Start(cancellationToken);
     176      cancellationTokenSource = CancellationTokenSource.CreateLinkedTokenSource(cancellationToken);
    179177      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) {
    186           try {
    187             ex.Flatten().Handle(x => x is OperationCanceledException);
    188           }
    189           catch (AggregateException remaining) {
    190             if (remaining.InnerExceptions.Count == 1) OnExceptionOccurred(remaining.InnerExceptions[0]);
    191             else OnExceptionOccurred(remaining);
    192           }
    193         }
    194         cancellationTokenSource.Dispose();
    195         cancellationTokenSource = null;
    196 
    197         if (stopPending) ExecutionStack.Clear();
    198         if (stopPending || !CanContinue) OnStopped();
    199         else OnPaused();
    200       });
    201     }
    202 
     178
     179      try {
     180        Run(cancellationTokenSource.Token);
     181      } catch (OperationCanceledException) {
     182      } catch (AggregateException ae) {
     183        OnExceptionOccurred(ae.InnerExceptions.SingleOrDefault() ?? ae);
     184      } catch (Exception e) {
     185        OnExceptionOccurred(e);
     186      }
     187
     188      cancellationTokenSource.Dispose();
     189      cancellationTokenSource = null;
     190      if (stopPending) ExecutionStack.Clear();
     191      if (stopPending || !CanContinue) OnStopped();
     192      else OnPaused();
     193    }
    203194    protected override void OnStarted() {
    204195      Log.LogMessage("Engine started");
     
    250241          ProcessNextOperation(false, cancellationToken);
    251242        cancellationToken.ThrowIfCancellationRequested();
    252       }
    253       finally {
     243      } finally {
    254244        timer.Stop();
    255245        ExecutionTime += DateTime.UtcNow - lastUpdateTime;
     
    317307          }
    318308          CurrentOperation = null;
    319         }
    320         catch (Exception ex) {
     309        } catch (Exception ex) {
    321310          if (ex is OperationCanceledException) throw ex;
    322311          else throw new OperatorExecutionException(operation.Operator, ex);
Note: See TracChangeset for help on using the changeset viewer.