- Timestamp:
- 07/26/17 15:48:32 (7 years ago)
- Location:
- trunk/sources
- Files:
-
- 3 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.Optimization
- Property svn:mergeinfo changed
/branches/Async/HeuristicLab.Optimization (added) merged: 13349,13354,13401,15065,15215,15232,15280-15281,15284
- Property svn:mergeinfo changed
-
trunk/sources/HeuristicLab.Optimization/3.3/Algorithms/BasicAlgorithm.cs
r14523 r15287 21 21 22 22 using System; 23 using System.Linq; 23 24 using System.Threading; 24 using System.Threading.Tasks;25 25 using HeuristicLab.Common; 26 26 using HeuristicLab.Core; … … 71 71 } 72 72 73 public override void Start( ) {74 base.Start( );75 CancellationTokenSource = new CancellationTokenSource();73 public override void Start(CancellationToken cancellationToken) { 74 base.Start(cancellationToken); 75 CancellationTokenSource = CancellationTokenSource.CreateLinkedTokenSource(cancellationToken); 76 76 pausePending = false; 77 77 OnStarted(); 78 78 79 Task task = Task.Factory.StartNew(Run, CancellationTokenSource.Token, CancellationTokenSource.Token); 80 task.ContinueWith(t => { 81 try { 82 t.Wait(); 83 } 84 catch (AggregateException ex) { 85 try { 86 ex.Flatten().Handle(x => x is OperationCanceledException); 87 } 88 catch (AggregateException remaining) { 89 if (remaining.InnerExceptions.Count == 1) OnExceptionOccurred(remaining.InnerExceptions[0]); 90 else OnExceptionOccurred(remaining); 91 } 92 } 93 CancellationTokenSource.Dispose(); 94 CancellationTokenSource = null; 95 if (pausePending) OnPaused(); 96 else OnStopped(); 97 }); 79 try { 80 Run((object)cancellationTokenSource.Token); 81 } catch (OperationCanceledException) { 82 } catch (AggregateException ae) { 83 OnExceptionOccurred(ae.InnerExceptions.SingleOrDefault() ?? ae); 84 } catch (Exception e) { 85 OnExceptionOccurred(e); 86 } 87 88 CancellationTokenSource.Dispose(); 89 CancellationTokenSource = null; 90 if (pausePending) OnPaused(); 91 else OnStopped(); 98 92 } 99 93
Note: See TracChangeset
for help on using the changeset viewer.