Changeset 13349 for branches/Async/HeuristicLab.Core/3.3
- Timestamp:
- 11/23/15 21:18:26 (9 years ago)
- Location:
- branches/Async/HeuristicLab.Core/3.3
- Files:
-
- 3 edited
Legend:
- Unmodified
- Added
- Removed
-
branches/Async/HeuristicLab.Core/3.3/Engine.cs
r12012 r13349 82 82 } 83 83 84 public override void Start() {85 base.Start();84 public override async Task StartAsync(CancellationToken cancellationToken) { 85 await base.StartAsync(cancellationToken); 86 86 cancellationTokenSource = new CancellationTokenSource(); 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) { 88 using (var cts = CancellationTokenSource.CreateLinkedTokenSource(cancellationTokenSource.Token, cancellationToken)) { 89 Task task = Task.Factory.StartNew(Run, cts.Token, cts.Token); 90 await task.ContinueWith(t => { 94 91 try { 95 ex.Flatten().Handle(x => x is OperationCanceledException);92 t.Wait(); 96 93 } 97 catch (AggregateException remaining) { 98 if (remaining.InnerExceptions.Count == 1) OnExceptionOccurred(remaining.InnerExceptions[0]); 99 else OnExceptionOccurred(remaining); 94 catch (AggregateException ex) { 95 try { 96 ex.Flatten().Handle(x => x is OperationCanceledException); 97 } 98 catch (AggregateException remaining) { 99 if (remaining.InnerExceptions.Count == 1) OnExceptionOccurred(remaining.InnerExceptions[0]); 100 else OnExceptionOccurred(remaining); 101 } 100 102 } 101 }102 cancellationTokenSource.Dispose();103 cancellationTokenSource = null;104 if (stopPending) executionStack.Clear();105 if (executionStack.Count == 0) OnStopped();106 else OnPaused();107 } );103 cancellationTokenSource.Dispose(); 104 cancellationTokenSource = null; 105 if (stopPending) executionStack.Clear(); 106 if (executionStack.Count == 0) OnStopped(); 107 else OnPaused(); 108 }); 109 } 108 110 } 109 111 protected override void OnStarted() { -
branches/Async/HeuristicLab.Core/3.3/Executable.cs
r12012 r13349 22 22 using System; 23 23 using System.Drawing; 24 using System.Threading; 25 using System.Threading.Tasks; 24 26 using HeuristicLab.Common; 25 27 using HeuristicLab.Persistence.Default.CompositeSerializers.Storable; … … 82 84 ExecutionTime = TimeSpan.Zero; 83 85 } 84 public virtual void Start() { 86 public void Start() { 87 StartAsync().Wait(); 88 } 89 public async Task StartAsync() { 90 await StartAsync(new CancellationToken()); 91 } 92 public virtual async Task StartAsync(CancellationToken cancellationToken) { 85 93 if ((ExecutionState != ExecutionState.Prepared) && (ExecutionState != ExecutionState.Paused)) 86 94 throw new InvalidOperationException(string.Format("Start not allowed in execution state \"{0}\".", ExecutionState)); -
branches/Async/HeuristicLab.Core/3.3/Interfaces/IExecutable.cs
r12012 r13349 21 21 22 22 using System; 23 using System.Threading; 24 using System.Threading.Tasks; 23 25 using HeuristicLab.Common; 24 26 … … 30 32 void Prepare(); 31 33 void Start(); 34 Task StartAsync(); 35 Task StartAsync(CancellationToken cancellationToken); 32 36 void Pause(); 33 37 void Stop();
Note: See TracChangeset
for help on using the changeset viewer.