- Timestamp:
- 06/26/17 09:45:36 (7 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
branches/Async/HeuristicLab.Optimization/3.3/Algorithms/BasicAlgorithm.cs
r13349 r15065 61 61 } 62 62 63 public override async Task StartAsync(CancellationToken cancellationToken) {64 await base.StartAsync(cancellationToken);63 public override void Start() { 64 base.Start(); 65 65 CancellationTokenSource = new CancellationTokenSource(); 66 66 67 67 OnStarted(); 68 using (var cts = CancellationTokenSource.CreateLinkedTokenSource(cancellationTokenSource.Token, cancellationToken)) { 69 Task task = Task.Factory.StartNew(Run, cts.Token, cts.Token); 70 await task.ContinueWith(t => { 68 Task task = Task.Factory.StartNew(Run, cancellationTokenSource.Token, cancellationTokenSource.Token); 69 task.ContinueWith(t => { 70 try { 71 t.Wait(); 72 } catch (AggregateException ex) { 71 73 try { 72 t.Wait(); 74 ex.Flatten().Handle(x => x is OperationCanceledException); 75 } catch (AggregateException remaining) { 76 if (remaining.InnerExceptions.Count == 1) OnExceptionOccurred(remaining.InnerExceptions[0]); 77 else OnExceptionOccurred(remaining); 73 78 } 74 catch (AggregateException ex) { 75 try { 76 ex.Flatten().Handle(x => x is OperationCanceledException); 77 } 78 catch (AggregateException remaining) { 79 if (remaining.InnerExceptions.Count == 1) OnExceptionOccurred(remaining.InnerExceptions[0]); 80 else OnExceptionOccurred(remaining); 81 } 82 } 83 CancellationTokenSource.Dispose(); 84 CancellationTokenSource = null; 85 OnStopped(); 86 }); 87 } 79 } 80 CancellationTokenSource.Dispose(); 81 CancellationTokenSource = null; 82 OnStopped(); 83 }); 88 84 } 89 85 … … 110 106 try { 111 107 Run(cancellationToken); 112 } 113 finally { 108 } finally { 114 109 timer.Elapsed -= new System.Timers.ElapsedEventHandler(timer_Elapsed); 115 110 timer.Stop();
Note: See TracChangeset
for help on using the changeset viewer.