Changeset 15287 for trunk/sources/HeuristicLab.Optimization/3.3/Algorithms
- Timestamp:
- 07/26/17 15:48:32 (7 years ago)
- Location:
- trunk/sources
- Files:
-
- 5 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/Algorithm.cs
r14433 r15287 24 24 using System.Drawing; 25 25 using System.Linq; 26 using System.Threading; 27 using System.Threading.Tasks; 26 28 using HeuristicLab.Collections; 27 29 using HeuristicLab.Common; … … 203 205 } 204 206 public virtual void Start() { 207 Start(CancellationToken.None); 208 } 209 public virtual void Start(CancellationToken cancellationToken) { 205 210 if ((ExecutionState != ExecutionState.Prepared) && (ExecutionState != ExecutionState.Paused)) 206 211 throw new InvalidOperationException(string.Format("Start not allowed in execution state \"{0}\".", ExecutionState)); 212 } 213 public virtual async Task StartAsync() { await StartAsync(CancellationToken.None); } 214 public virtual async Task StartAsync(CancellationToken cancellationToken) { 215 await AsyncHelper.DoAsync(Start, cancellationToken); 207 216 } 208 217 public virtual void Pause() { -
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 -
trunk/sources/HeuristicLab.Optimization/3.3/Algorithms/EngineAlgorithm.cs
r14185 r15287 168 168 } 169 169 } 170 public override void Start( ) {171 base.Start( );172 if (engine != null) engine.Start( );170 public override void Start(System.Threading.CancellationToken cancellationToken) { 171 base.Start(cancellationToken); 172 if (engine != null) engine.Start(cancellationToken); 173 173 } 174 174 public override void Pause() {
Note: See TracChangeset
for help on using the changeset viewer.