- Timestamp:
- 07/26/17 15:48:32 (7 years ago)
- Location:
- trunk/sources
- Files:
-
- 2 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/sources
- Property svn:mergeinfo changed
/branches/Async (added) merged: 13329,13349,13354-13355,13401,15065,15190,15204,15212,15215-15216,15232,15280-15281,15284,15286
- Property svn:mergeinfo changed
-
trunk/sources/HeuristicLab.Algorithms.Benchmarks/3.3/BenchmarkAlgorithm.cs
r14185 r15287 302 302 } 303 303 public void Start() { 304 cancellationTokenSource = new CancellationTokenSource(); 304 Start(CancellationToken.None); 305 } 306 public void Start(CancellationToken cancellationToken) { 307 cancellationTokenSource = CancellationTokenSource.CreateLinkedTokenSource(cancellationToken); 305 308 OnStarted(); 306 Task task = Task.Factory.StartNew(Run, cancellationTokenSource.Token, cancellationTokenSource.Token); 307 task.ContinueWith(t => { 308 try { 309 t.Wait(); 310 } 311 catch (AggregateException ex) { 312 try { 313 ex.Flatten().Handle(x => x is OperationCanceledException); 314 } 315 catch (AggregateException remaining) { 316 if (remaining.InnerExceptions.Count == 1) OnExceptionOccurred(remaining.InnerExceptions[0]); 317 else OnExceptionOccurred(remaining); 318 } 319 } 320 321 cancellationTokenSource.Dispose(); 322 cancellationTokenSource = null; 323 OnStopped(); 324 }); 309 310 try { 311 Run(cancellationTokenSource.Token); 312 } catch (OperationCanceledException) { 313 } catch (AggregateException ae) { 314 OnExceptionOccurred(ae.InnerExceptions.SingleOrDefault() ?? ae); 315 } catch (Exception e) { 316 OnExceptionOccurred(e); 317 } 318 319 cancellationTokenSource.Dispose(); 320 cancellationTokenSource = null; 321 OnStopped(); 322 } 323 public async Task StartAsync() { await StartAsync(CancellationToken.None); } 324 public async Task StartAsync(CancellationToken cancellationToken) { 325 await AsyncHelper.DoAsync(Start, cancellationToken); 325 326 } 326 327 … … 346 347 Benchmark.TimeLimit = timelimit; 347 348 Benchmark.Run(cancellationToken, results); 348 } 349 catch (OperationCanceledException) { 350 } 351 finally { 349 } catch (OperationCanceledException) { 350 } finally { 352 351 timer.Elapsed -= new System.Timers.ElapsedEventHandler(timer_Elapsed); 353 352 timer.Stop();
Note: See TracChangeset
for help on using the changeset viewer.