Changeset 15065 for branches/Async/HeuristicLab.DebugEngine
- Timestamp:
- 06/26/17 09:45:36 (7 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
branches/Async/HeuristicLab.DebugEngine/3.3/DebugEngine.cs
r13349 r15065 23 23 using System.Linq; 24 24 using System.Threading; 25 using System.Threading.Tasks;26 25 using HeuristicLab.Common; 27 26 using HeuristicLab.Core; … … 161 160 while (skipStackOperations && !(CurrentOperation is IAtomicOperation) && CanContinue) 162 161 ProcessNextOperation(true, cancellationTokenSource.Token); 163 } 164 catch (Exception ex) { 162 } catch (Exception ex) { 165 163 OnExceptionOccurred(ex); 166 164 } … … 174 172 } 175 173 176 public override async Task StartAsync(CancellationToken cancellationToken) {177 await base.StartAsync(cancellationToken);178 cancellationTokenSource = new CancellationTokenSource();174 public override void Start(CancellationToken cancellationToken) { 175 base.Start(cancellationToken); 176 cancellationTokenSource = CancellationTokenSource.CreateLinkedTokenSource(cancellationToken); 179 177 stopPending = false; 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 => { 183 try { 184 t.Wait(); 185 } 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 } 194 } 195 cancellationTokenSource.Dispose(); 196 cancellationTokenSource = null; 197 198 if (stopPending) ExecutionStack.Clear(); 199 if (stopPending || !CanContinue) OnStopped(); 200 else OnPaused(); 201 }); 202 } 203 } 204 178 179 try { 180 Run(cancellationTokenSource.Token); 181 } catch (OperationCanceledException) { 182 } catch (AggregateException ae) { 183 if (ae.InnerExceptions.Count == 1) OnExceptionOccurred(ae.InnerExceptions[0]); 184 else OnExceptionOccurred(ae); 185 } catch (Exception e) { 186 OnExceptionOccurred(e); 187 } 188 189 cancellationTokenSource.Dispose(); 190 cancellationTokenSource = null; 191 if (stopPending) ExecutionStack.Clear(); 192 if (stopPending || !CanContinue) OnStopped(); 193 else OnPaused(); 194 } 205 195 protected override void OnStarted() { 206 196 Log.LogMessage("Engine started"); … … 252 242 ProcessNextOperation(false, cancellationToken); 253 243 cancellationToken.ThrowIfCancellationRequested(); 254 } 255 finally { 244 } finally { 256 245 timer.Stop(); 257 246 ExecutionTime += DateTime.UtcNow - lastUpdateTime; … … 319 308 } 320 309 CurrentOperation = null; 321 } 322 catch (Exception ex) { 310 } catch (Exception ex) { 323 311 if (ex is OperationCanceledException) throw ex; 324 312 else throw new OperatorExecutionException(operation.Operator, ex);
Note: See TracChangeset
for help on using the changeset viewer.