Changeset 15287 for trunk/sources/HeuristicLab.Core/3.3/Engine.cs
- 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.Core
- Property svn:mergeinfo changed
/branches/Async/HeuristicLab.Core (added) merged: 13349,13354,13401,15065,15232,15280-15281
- Property svn:mergeinfo changed
-
trunk/sources/HeuristicLab.Core/3.3/Engine.cs
r14185 r15287 22 22 using System; 23 23 using System.Collections.Generic; 24 using System.Linq; 24 25 using System.Threading; 25 using System.Threading.Tasks;26 26 using HeuristicLab.Common; 27 27 using HeuristicLab.Persistence.Default.CompositeSerializers.Storable; … … 82 82 } 83 83 84 public override void Start( ) {85 base.Start( );86 cancellationTokenSource = new CancellationTokenSource();84 public override void Start(CancellationToken cancellationToken) { 85 base.Start(cancellationToken); 86 cancellationTokenSource = CancellationTokenSource.CreateLinkedTokenSource(cancellationToken); 87 87 stopPending = false; 88 Task task = Task.Factory.StartNew(Run, cancellationTokenSource.Token, cancellationTokenSource.Token); 89 task.ContinueWith(t => { 90 try { 91 t.Wait(); 92 } 93 catch (AggregateException ex) { 94 try { 95 ex.Flatten().Handle(x => x is OperationCanceledException); 96 } 97 catch (AggregateException remaining) { 98 if (remaining.InnerExceptions.Count == 1) OnExceptionOccurred(remaining.InnerExceptions[0]); 99 else OnExceptionOccurred(remaining); 100 } 101 } 102 cancellationTokenSource.Dispose(); 103 cancellationTokenSource = null; 104 if (stopPending) executionStack.Clear(); 105 if (executionStack.Count == 0) OnStopped(); 106 else OnPaused(); 107 }); 88 89 try { 90 Run((object)cancellationTokenSource.Token); 91 } catch (OperationCanceledException) { 92 } catch (AggregateException ae) { 93 OnExceptionOccurred(ae.InnerExceptions.SingleOrDefault() ?? ae); 94 } catch (Exception e) { 95 OnExceptionOccurred(e); 96 } 97 98 cancellationTokenSource.Dispose(); 99 cancellationTokenSource = null; 100 if (stopPending) executionStack.Clear(); 101 if (executionStack.Count == 0) OnStopped(); 102 else OnPaused(); 108 103 } 109 104 protected override void OnStarted() { … … 152 147 try { 153 148 Run(cancellationToken); 154 } 155 finally { 149 } finally { 156 150 timer.Elapsed -= new System.Timers.ElapsedEventHandler(timer_Elapsed); 157 151 timer.Stop();
Note: See TracChangeset
for help on using the changeset viewer.