- Timestamp:
- 06/26/17 09:45:36 (8 years ago)
- Location:
- branches/Async
- Files:
-
- 1 deleted
- 23 edited
Legend:
- Unmodified
- Added
- Removed
-
branches/Async/HeuristicLab.Algorithms.Benchmarks/3.3/BenchmarkAlgorithm.cs
r13354 r15065 302 302 } 303 303 public void Start() { 304 StartAsync().Wait(); 305 } 306 public async Task StartAsync() { 307 await StartAsync(CancellationToken.None); 308 } 304 Start(CancellationToken.None); 305 } 306 public void Start(CancellationToken cancellationToken) { 307 cancellationTokenSource = CancellationTokenSource.CreateLinkedTokenSource(cancellationToken); 308 OnStarted(); 309 310 try { 311 Run(cancellationTokenSource.Token); 312 } catch (OperationCanceledException) { 313 } catch (AggregateException ae) { 314 if (ae.InnerExceptions.Count == 1) OnExceptionOccurred(ae.InnerExceptions[0]); 315 else OnExceptionOccurred(ae); 316 } catch (Exception e) { 317 OnExceptionOccurred(e); 318 } 319 320 cancellationTokenSource.Dispose(); 321 cancellationTokenSource = null; 322 OnStopped(); 323 } 324 public async Task StartAsync() { await StartAsync(CancellationToken.None); } 309 325 public async Task StartAsync(CancellationToken cancellationToken) { 310 cancellationTokenSource = new CancellationTokenSource(); 311 OnStarted(); 312 using (var cts = CancellationTokenSource.CreateLinkedTokenSource(cancellationTokenSource.Token, cancellationToken)) { 313 Task task = Task.Factory.StartNew(Run, cts.Token, cts.Token); 314 await task.ContinueWith(t => { 315 try { 316 t.Wait(); 317 } 318 catch (AggregateException ex) { 319 try { 320 ex.Flatten().Handle(x => x is OperationCanceledException); 321 } 322 catch (AggregateException remaining) { 323 if (remaining.InnerExceptions.Count == 1) OnExceptionOccurred(remaining.InnerExceptions[0]); 324 else OnExceptionOccurred(remaining); 325 } 326 } 327 328 cancellationTokenSource.Dispose(); 329 cancellationTokenSource = null; 330 OnStopped(); 331 }); 332 } 333 } 326 await Task.Factory.StartNew((ct) => Start((CancellationToken)ct), cancellationToken, cancellationToken); 327 } 328 334 329 private void Run(object state) { 335 330 CancellationToken cancellationToken = (CancellationToken)state; … … 353 348 Benchmark.TimeLimit = timelimit; 354 349 Benchmark.Run(cancellationToken, results); 355 } 356 catch (OperationCanceledException) { 357 } 358 finally { 350 } catch (OperationCanceledException) { 351 } finally { 359 352 timer.Elapsed -= new System.Timers.ElapsedEventHandler(timer_Elapsed); 360 353 timer.Stop(); -
branches/Async/HeuristicLab.Algorithms.DataAnalysis/3.4/CrossValidation.cs
r13354 r15065 40 40 [StorableClass] 41 41 public sealed class CrossValidation : ParameterizedNamedItem, IAlgorithm, IStorableContent { 42 private readonly ManualResetEvent signaler = new ManualResetEvent(true);43 private CancellationToken cancellationToken;42 private SemaphoreSlim ticket; 43 private ManualResetEventSlim signal; 44 44 45 45 public CrossValidation() … … 269 269 Prepare(); 270 270 } 271 271 272 public void Start() { 272 StartAsync().Wait(); 273 } 274 public async Task StartAsync() { 275 await StartAsync(CancellationToken.None); 276 } 273 Start(CancellationToken.None); 274 } 275 public void Start(CancellationToken cancellationToken) { 276 if ((ExecutionState != ExecutionState.Prepared) && (ExecutionState != ExecutionState.Paused)) 277 throw new InvalidOperationException(string.Format("Start not allowed in execution state \"{0}\".", ExecutionState)); 278 279 if (Algorithm == null) return; 280 //create cloned algorithms 281 if (clonedAlgorithms.Count == 0) { 282 int testSamplesCount = (SamplesEnd.Value - SamplesStart.Value) / Folds.Value; 283 284 for (int i = 0; i < Folds.Value; i++) { 285 IAlgorithm clonedAlgorithm = (IAlgorithm)algorithm.Clone(); 286 clonedAlgorithm.Name = algorithm.Name + " Fold " + i; 287 IDataAnalysisProblem problem = clonedAlgorithm.Problem as IDataAnalysisProblem; 288 ISymbolicDataAnalysisProblem symbolicProblem = problem as ISymbolicDataAnalysisProblem; 289 290 int testStart = (i * testSamplesCount) + SamplesStart.Value; 291 int testEnd = (i + 1) == Folds.Value ? SamplesEnd.Value : (i + 1) * testSamplesCount + SamplesStart.Value; 292 293 problem.ProblemData.TrainingPartition.Start = SamplesStart.Value; 294 problem.ProblemData.TrainingPartition.End = SamplesEnd.Value; 295 problem.ProblemData.TestPartition.Start = testStart; 296 problem.ProblemData.TestPartition.End = testEnd; 297 DataAnalysisProblemData problemData = problem.ProblemData as DataAnalysisProblemData; 298 if (problemData != null) { 299 problemData.TrainingPartitionParameter.Hidden = false; 300 problemData.TestPartitionParameter.Hidden = false; 301 } 302 303 if (symbolicProblem != null) { 304 symbolicProblem.FitnessCalculationPartition.Start = SamplesStart.Value; 305 symbolicProblem.FitnessCalculationPartition.End = SamplesEnd.Value; 306 } 307 clonedAlgorithm.Prepare(); 308 clonedAlgorithms.Add(clonedAlgorithm); 309 } 310 } 311 312 OnStarted(); 313 ticket = new SemaphoreSlim(NumberOfWorkers.Value); 314 signal = new ManualResetEventSlim(false); 315 316 //start prepared or paused cloned algorithms 317 foreach (IAlgorithm clonedAlgorithm in clonedAlgorithms) { 318 if (pausePending || stopPending) break; 319 if (clonedAlgorithm.ExecutionState == ExecutionState.Prepared || 320 clonedAlgorithm.ExecutionState == ExecutionState.Paused) { 321 ticket.Wait(); 322 clonedAlgorithm.StartAsync(cancellationToken); 323 } 324 } 325 326 signal.Wait(); 327 if (pausePending) OnPaused(); 328 else OnStopped(); 329 } 330 331 public async Task StartAsync() { await StartAsync(CancellationToken.None); } 277 332 public async Task StartAsync(CancellationToken cancellationToken) { 278 this.cancellationToken = cancellationToken; 279 signaler.Reset(); 280 await Task.Run(() => { 281 if ((ExecutionState != ExecutionState.Prepared) && (ExecutionState != ExecutionState.Paused)) 282 throw new InvalidOperationException(string.Format("Start not allowed in execution state \"{0}\".", ExecutionState)); 283 284 if (Algorithm != null) { 285 //create cloned algorithms 286 if (clonedAlgorithms.Count == 0) { 287 int testSamplesCount = (SamplesEnd.Value - SamplesStart.Value) / Folds.Value; 288 289 for (int i = 0; i < Folds.Value; i++) { 290 IAlgorithm clonedAlgorithm = (IAlgorithm)algorithm.Clone(); 291 clonedAlgorithm.Name = algorithm.Name + " Fold " + i; 292 IDataAnalysisProblem problem = clonedAlgorithm.Problem as IDataAnalysisProblem; 293 ISymbolicDataAnalysisProblem symbolicProblem = problem as ISymbolicDataAnalysisProblem; 294 295 int testStart = (i * testSamplesCount) + SamplesStart.Value; 296 int testEnd = (i + 1) == Folds.Value ? SamplesEnd.Value : (i + 1) * testSamplesCount + SamplesStart.Value; 297 298 problem.ProblemData.TrainingPartition.Start = SamplesStart.Value; 299 problem.ProblemData.TrainingPartition.End = SamplesEnd.Value; 300 problem.ProblemData.TestPartition.Start = testStart; 301 problem.ProblemData.TestPartition.End = testEnd; 302 DataAnalysisProblemData problemData = problem.ProblemData as DataAnalysisProblemData; 303 if (problemData != null) { 304 problemData.TrainingPartitionParameter.Hidden = false; 305 problemData.TestPartitionParameter.Hidden = false; 306 } 307 308 if (symbolicProblem != null) { 309 symbolicProblem.FitnessCalculationPartition.Start = SamplesStart.Value; 310 symbolicProblem.FitnessCalculationPartition.End = SamplesEnd.Value; 311 } 312 clonedAlgorithm.Prepare(); 313 clonedAlgorithms.Add(clonedAlgorithm); 314 } 315 } 316 317 //start prepared or paused cloned algorithms 318 int startedAlgorithms = 0; 319 foreach (IAlgorithm clonedAlgorithm in clonedAlgorithms) { 320 if (startedAlgorithms < NumberOfWorkers.Value) { 321 if (clonedAlgorithm.ExecutionState == ExecutionState.Prepared || 322 clonedAlgorithm.ExecutionState == ExecutionState.Paused) { 323 324 // start and wait until the alg is started 325 using (var signal = new ManualResetEvent(false)) { 326 EventHandler signalSetter = (sender, args) => { signal.Set(); }; 327 clonedAlgorithm.Started += signalSetter; 328 clonedAlgorithm.StartAsync(cancellationToken); 329 signal.WaitOne(); 330 clonedAlgorithm.Started -= signalSetter; 331 332 startedAlgorithms++; 333 } 334 } 335 } 336 } 337 OnStarted(); 338 } 339 }, cancellationToken); 333 await Task.Factory.StartNew((ct) => Start((CancellationToken)ct), cancellationToken, cancellationToken); 340 334 } 341 335 … … 346 340 if (!pausePending) { 347 341 pausePending = true; 348 PauseAllClonedAlgorithms(); 349 } 350 } 351 private void PauseAllClonedAlgorithms() { 352 foreach (IAlgorithm clonedAlgorithm in clonedAlgorithms) { 353 if (clonedAlgorithm.ExecutionState == ExecutionState.Started) 354 clonedAlgorithm.Pause(); 342 var toPause = clonedAlgorithms.Where(x => x.ExecutionState == ExecutionState.Started); 343 if (toPause.Any()) { 344 foreach (var optimizer in toPause) { 345 // a race-condition may occur when the optimizer has changed the state by itself in the meantime 346 try { optimizer.Pause(); } catch (InvalidOperationException) { } 347 } 348 } 349 if (ExecutionState != ExecutionState.Paused) OnPaused(); 355 350 } 356 351 } … … 363 358 if (!stopPending) { 364 359 stopPending = true; 365 StopAllClonedAlgorithms();366 }367 }368 private void StopAllClonedAlgorithms() {369 foreach (IAlgorithm clonedAlgorithm in clonedAlgorithms) {370 if (clonedAlgorithm.ExecutionState == ExecutionState.Started ||371 clonedAlgorithm.ExecutionState == ExecutionState.Paused)372 clonedAlgorithm.Stop();360 var toStop = clonedAlgorithms.Where(x => x.ExecutionState == ExecutionState.Started || x.ExecutionState == ExecutionState.Paused); 361 if (toStop.Any()) { 362 foreach (var optimizer in toStop) { 363 // a race-condition may occur when the optimizer has changed the state by itself in the meantime 364 try { optimizer.Stop(); } catch (InvalidOperationException) { } 365 } 366 } 367 if (ExecutionState != ExecutionState.Stopped) OnStopped(); 373 368 } 374 369 } … … 602 597 private void Algorithm_ExecutionStateChanged(object sender, EventArgs e) { 603 598 switch (Algorithm.ExecutionState) { 604 case ExecutionState.Prepared: OnPrepared(); 599 case ExecutionState.Prepared: 600 OnPrepared(); 605 601 break; 606 602 case ExecutionState.Started: throw new InvalidOperationException("Algorithm template can not be started."); 607 603 case ExecutionState.Paused: throw new InvalidOperationException("Algorithm template can not be paused."); 608 case ExecutionState.Stopped: OnStopped(); 604 case ExecutionState.Stopped: 605 OnStopped(); 609 606 break; 610 607 } … … 674 671 private void ClonedAlgorithm_Paused(object sender, EventArgs e) { 675 672 lock (locker) { 676 if (pausePending && clonedAlgorithms.All(alg => alg.ExecutionState != ExecutionState.Started)) 677 OnPaused(); 673 if (ExecutionState != ExecutionState.Paused) { 674 if (clonedAlgorithms.All(alg => alg.ExecutionState != ExecutionState.Started)) { 675 pausePending = true; 676 signal.Set(); 677 ticket.Release(); 678 } 679 } 678 680 } 679 681 } … … 681 683 private void ClonedAlgorithm_Stopped(object sender, EventArgs e) { 682 684 lock (locker) { 683 if (!stopPending && ExecutionState == ExecutionState.Started) {684 IAlgorithm preparedAlgorithm = clonedAlgorithms.FirstOrDefault(alg => alg.ExecutionState == ExecutionState.Prepared ||685 alg.ExecutionState == ExecutionState.Paused);686 if (preparedAlgorithm != null) preparedAlgorithm.StartAsync(cancellationToken);687 }688 685 if (ExecutionState != ExecutionState.Stopped) { 689 if (clonedAlgorithms.All(alg => alg.ExecutionState == ExecutionState.Stopped)) 690 OnStopped(); 691 else if (stopPending && 692 clonedAlgorithms.All( 693 alg => alg.ExecutionState == ExecutionState.Prepared || alg.ExecutionState == ExecutionState.Stopped)) 694 OnStopped(); 686 if (clonedAlgorithms.All(alg => alg.ExecutionState == ExecutionState.Stopped || stopPending && alg.ExecutionState == ExecutionState.Prepared)) { 687 stopPending = true; 688 signal.Set(); 689 } 690 ticket.Release(); 695 691 } 696 692 } … … 727 723 pausePending = false; 728 724 ExecutionState = ExecutionState.Paused; 729 signaler.Set();730 725 EventHandler handler = Paused; 731 726 if (handler != null) handler(this, EventArgs.Empty); … … 740 735 runs.Add(new Run(string.Format("{0} Run {1}", Name, runsCounter), this)); 741 736 ExecutionState = ExecutionState.Stopped; 742 signaler.Set();743 737 EventHandler handler = Stopped; 744 738 if (handler != null) handler(this, EventArgs.Empty); -
branches/Async/HeuristicLab.Algorithms.DataAnalysis/3.4/FixedDataAnalysisAlgorithm.cs
r13349 r15065 22 22 using System; 23 23 using System.Threading; 24 using System.Threading.Tasks;25 24 using HeuristicLab.Common; 26 25 using HeuristicLab.Optimization; … … 70 69 } 71 70 72 public override async Task StartAsync(CancellationToken cancellationToken) {73 await base.StartAsync(cancellationToken);74 var cancellationTokenSource = new CancellationTokenSource();71 public override void Start(CancellationToken cancellationToken) { 72 base.Start(cancellationToken); 73 OnStarted(); 75 74 76 OnStarted(); 77 using (var cts = CancellationTokenSource.CreateLinkedTokenSource(cancellationTokenSource.Token, cancellationToken)) { 78 Task task = Task.Factory.StartNew(Run, cts.Token, cts.Token); 79 await task.ContinueWith(t => { 80 try { 81 t.Wait(); 82 } 83 catch (AggregateException ex) { 84 try { 85 ex.Flatten().Handle(x => x is OperationCanceledException); 86 } 87 catch (AggregateException remaining) { 88 if (remaining.InnerExceptions.Count == 1) OnExceptionOccurred(remaining.InnerExceptions[0]); 89 else OnExceptionOccurred(remaining); 90 } 91 } 92 cancellationTokenSource.Dispose(); 93 cancellationTokenSource = null; 94 OnStopped(); 95 }); 75 try { 76 Run(cancellationToken); 77 } catch (OperationCanceledException) { 78 } catch (AggregateException ae) { 79 if (ae.InnerExceptions.Count == 1) OnExceptionOccurred(ae.InnerExceptions[0]); 80 else OnExceptionOccurred(ae); 81 } catch (Exception e) { 82 OnExceptionOccurred(e); 96 83 } 84 85 OnStopped(); 97 86 } 98 87 private void Run(object state) { -
branches/Async/HeuristicLab.Clients.OKB/3.3/RunCreation/EmptyAlgorithm.cs
r13349 r15065 21 21 22 22 using System; 23 using System.Threading;24 using System.Threading.Tasks;25 23 using HeuristicLab.Common; 26 24 using HeuristicLab.Core; … … 82 80 throw new InvalidOperationException(string.IsNullOrEmpty(exceptionMessage) ? "Cannot prepare an EmptyAlgorithm." : exceptionMessage); 83 81 } 84 public override async Task StartAsync(CancellationToken cancellationToken) {82 public override void Start() { 85 83 throw new InvalidOperationException(string.IsNullOrEmpty(exceptionMessage) ? "Cannot start an EmptyAlgorithm." : exceptionMessage); 86 84 } -
branches/Async/HeuristicLab.Clients.OKB/3.3/RunCreation/OKBAlgorithm.cs
r13354 r15065 252 252 } 253 253 public void Start() { 254 StartAsync().Wait(); 255 } 256 public async Task StartAsync() { 257 await StartAsync(CancellationToken.None); 258 } 259 public async Task StartAsync(CancellationToken cancellationToken) { 254 Start(CancellationToken.None); 255 } 256 public void Start(CancellationToken cancellationToken) { 260 257 CheckUserPermissions(); 261 258 if (!ClientInformation.Instance.ClientExists && storeRunsAutomatically) { 262 259 throw new MissingClientRegistrationException(); 263 260 } 264 await Algorithm.StartAsync(cancellationToken); 261 Algorithm.Start(cancellationToken); 262 } 263 public async Task StartAsync() { await StartAsync(CancellationToken.None); } 264 public async Task StartAsync(CancellationToken cancellationToken) { 265 await Task.Factory.StartNew((ct) => Start((CancellationToken)ct), cancellationToken, cancellationToken); 265 266 } 266 267 public void Pause() { -
branches/Async/HeuristicLab.Core/3.3/Engine.cs
r13349 r15065 23 23 using System.Collections.Generic; 24 24 using System.Threading; 25 using System.Threading.Tasks;26 25 using HeuristicLab.Common; 27 26 using HeuristicLab.Persistence.Default.CompositeSerializers.Storable; … … 82 81 } 83 82 84 public override async Task StartAsync(CancellationToken cancellationToken) {85 await base.StartAsync(cancellationToken);86 cancellationTokenSource = new CancellationTokenSource();83 public override void Start(CancellationToken cancellationToken) { 84 base.Start(cancellationToken); 85 cancellationTokenSource = CancellationTokenSource.CreateLinkedTokenSource(cancellationToken); 87 86 stopPending = false; 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 => { 91 try { 92 t.Wait(); 93 } 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 } 102 } 103 cancellationTokenSource.Dispose(); 104 cancellationTokenSource = null; 105 if (stopPending) executionStack.Clear(); 106 if (executionStack.Count == 0) OnStopped(); 107 else OnPaused(); 108 }); 87 88 try { 89 Run((object)cancellationTokenSource.Token); 90 } catch (OperationCanceledException) { 91 } catch (AggregateException ae) { 92 if (ae.InnerExceptions.Count == 1) OnExceptionOccurred(ae.InnerExceptions[0]); 93 else OnExceptionOccurred(ae); 94 } catch (Exception e) { 95 OnExceptionOccurred(e); 109 96 } 97 98 cancellationTokenSource.Dispose(); 99 cancellationTokenSource = null; 100 if (stopPending) executionStack.Clear(); 101 if (executionStack.Count == 0) OnStopped(); 102 else OnPaused(); 110 103 } 111 104 protected override void OnStarted() { … … 154 147 try { 155 148 Run(cancellationToken); 156 } 157 finally { 149 } finally { 158 150 timer.Elapsed -= new System.Timers.ElapsedEventHandler(timer_Elapsed); 159 151 timer.Stop(); -
branches/Async/HeuristicLab.Core/3.3/Executable.cs
r13354 r15065 84 84 ExecutionTime = TimeSpan.Zero; 85 85 } 86 public v oid Start() {87 Start Async().Wait();86 public virtual void Start() { 87 Start(CancellationToken.None); 88 88 } 89 public async Task StartAsync() { 90 await StartAsync(CancellationToken.None); 91 } 92 public virtual async Task StartAsync(CancellationToken cancellationToken) { 89 public virtual void Start(CancellationToken cancellationToken) { 93 90 if ((ExecutionState != ExecutionState.Prepared) && (ExecutionState != ExecutionState.Paused)) 94 91 throw new InvalidOperationException(string.Format("Start not allowed in execution state \"{0}\".", ExecutionState)); 92 } 93 public virtual async Task StartAsync() { await StartAsync(CancellationToken.None); } 94 public virtual async Task StartAsync(CancellationToken cancellationToken) { 95 await Task.Factory.StartNew((ct) => Start((CancellationToken)ct), cancellationToken, cancellationToken); 95 96 } 96 97 public virtual void Pause() { -
branches/Async/HeuristicLab.Core/3.3/Interfaces/IExecutable.cs
r13349 r15065 32 32 void Prepare(); 33 33 void Start(); 34 void Start(CancellationToken cancellationToken); 34 35 Task StartAsync(); 35 36 Task StartAsync(CancellationToken cancellationToken); -
branches/Async/HeuristicLab.DebugEngine/3.3/DebugEngine.cs
r13349 r15065 23 23 using System.Linq; 24 24 using System.Threading; 25 using System.Threading.Tasks;26 25 using HeuristicLab.Common; 27 26 using HeuristicLab.Core; … … 161 160 while (skipStackOperations && !(CurrentOperation is IAtomicOperation) && CanContinue) 162 161 ProcessNextOperation(true, cancellationTokenSource.Token); 163 } 164 catch (Exception ex) { 162 } catch (Exception ex) { 165 163 OnExceptionOccurred(ex); 166 164 } … … 174 172 } 175 173 176 public override async Task StartAsync(CancellationToken cancellationToken) {177 await base.StartAsync(cancellationToken);178 cancellationTokenSource = new CancellationTokenSource();174 public override void Start(CancellationToken cancellationToken) { 175 base.Start(cancellationToken); 176 cancellationTokenSource = CancellationTokenSource.CreateLinkedTokenSource(cancellationToken); 179 177 stopPending = false; 180 using (var cts = CancellationTokenSource.CreateLinkedTokenSource(cancellationTokenSource.Token, cancellationToken)) { 181 Task task = Task.Factory.StartNew(Run, cts.Token, cts.Token); 182 await task.ContinueWith(t => { 183 try { 184 t.Wait(); 185 } 186 catch (AggregateException ex) { 187 try { 188 ex.Flatten().Handle(x => x is OperationCanceledException); 189 } 190 catch (AggregateException remaining) { 191 if (remaining.InnerExceptions.Count == 1) OnExceptionOccurred(remaining.InnerExceptions[0]); 192 else OnExceptionOccurred(remaining); 193 } 194 } 195 cancellationTokenSource.Dispose(); 196 cancellationTokenSource = null; 197 198 if (stopPending) ExecutionStack.Clear(); 199 if (stopPending || !CanContinue) OnStopped(); 200 else OnPaused(); 201 }); 202 } 203 } 204 178 179 try { 180 Run(cancellationTokenSource.Token); 181 } catch (OperationCanceledException) { 182 } catch (AggregateException ae) { 183 if (ae.InnerExceptions.Count == 1) OnExceptionOccurred(ae.InnerExceptions[0]); 184 else OnExceptionOccurred(ae); 185 } catch (Exception e) { 186 OnExceptionOccurred(e); 187 } 188 189 cancellationTokenSource.Dispose(); 190 cancellationTokenSource = null; 191 if (stopPending) ExecutionStack.Clear(); 192 if (stopPending || !CanContinue) OnStopped(); 193 else OnPaused(); 194 } 205 195 protected override void OnStarted() { 206 196 Log.LogMessage("Engine started"); … … 252 242 ProcessNextOperation(false, cancellationToken); 253 243 cancellationToken.ThrowIfCancellationRequested(); 254 } 255 finally { 244 } finally { 256 245 timer.Stop(); 257 246 ExecutionTime += DateTime.UtcNow - lastUpdateTime; … … 319 308 } 320 309 CurrentOperation = null; 321 } 322 catch (Exception ex) { 310 } catch (Exception ex) { 323 311 if (ex is OperationCanceledException) throw ex; 324 312 else throw new OperatorExecutionException(operation.Operator, ex); -
branches/Async/HeuristicLab.Optimization/3.3/Algorithms/Algorithm.cs
r13354 r15065 204 204 Prepare(); 205 205 } 206 public void Start() { 207 StartAsync().Wait(); 208 } 209 public async Task StartAsync() { 210 await StartAsync(CancellationToken.None); 211 } 212 public virtual async Task StartAsync(CancellationToken cancellationToken) { 206 public virtual void Start() { 207 Start(CancellationToken.None); 208 } 209 public virtual void Start(CancellationToken cancellationToken) { 213 210 if ((ExecutionState != ExecutionState.Prepared) && (ExecutionState != ExecutionState.Paused)) 214 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 Task.Factory.StartNew((ct) => Start((CancellationToken)ct), cancellationToken, cancellationToken); 215 216 } 216 217 public virtual void Pause() { -
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(); -
branches/Async/HeuristicLab.Optimization/3.3/Algorithms/EngineAlgorithm.cs
r13349 r15065 22 22 using System; 23 23 using System.Linq; 24 using System.Threading;25 using System.Threading.Tasks;26 24 using HeuristicLab.Common; 27 25 using HeuristicLab.Core; 28 26 using HeuristicLab.Persistence.Default.CompositeSerializers.Storable; 29 27 using HeuristicLab.PluginInfrastructure; 30 using ExecutionContext = HeuristicLab.Core.ExecutionContext;31 28 32 29 namespace HeuristicLab.Optimization { … … 171 168 } 172 169 } 173 public override async Task StartAsync(CancellationToken cancellationToken) {174 await base.StartAsync(cancellationToken);175 if (engine != null) await engine.StartAsync(cancellationToken);170 public override void Start(System.Threading.CancellationToken cancellationToken) { 171 base.Start(cancellationToken); 172 if (engine != null) engine.Start(cancellationToken); 176 173 } 177 174 public override void Pause() { -
branches/Async/HeuristicLab.Optimization/3.3/MetaOptimizers/BatchRun.cs
r13354 r15065 41 41 [StorableClass] 42 42 public sealed class BatchRun : NamedItem, IOptimizer, IStorableContent { 43 private readonly ManualResetEvent signaler = new ManualResetEvent(true);44 private CancellationToken cancellationToken;45 46 43 public string Filename { get; set; } 47 44 … … 242 239 batchRunAction = BatchRunAction.Prepare; 243 240 // a race-condition may occur when the optimizer has changed the state by itself in the meantime 244 try { Optimizer.Prepare(clearRuns); } 245 catch (InvalidOperationException) { } 241 try { Optimizer.Prepare(clearRuns); } catch (InvalidOperationException) { } 246 242 } else { 247 243 ExecutionState = ExecutionState.Stopped; … … 249 245 } 250 246 public void Start() { 251 StartAsync().Wait(); 252 } 253 public async Task StartAsync() { 254 await StartAsync(CancellationToken.None); 255 } 247 Start(CancellationToken.None); 248 } 249 public void Start(CancellationToken cancellationToken) { 250 if ((ExecutionState != ExecutionState.Prepared) && (ExecutionState != ExecutionState.Paused)) 251 throw new InvalidOperationException(string.Format("Start not allowed in execution state \"{0}\".", ExecutionState)); 252 if (Optimizer == null) return; 253 batchRunAction = BatchRunAction.Start; 254 if (Optimizer.ExecutionState == ExecutionState.Stopped) Optimizer.Prepare(); 255 for (int i = repetitionsCounter; i < repetitions; i++) { 256 // a race-condition may occur when the optimizer has changed the state by itself in the meantime 257 try { Optimizer.Start(cancellationToken); } catch (InvalidOperationException) { } 258 if (ExecutionState == ExecutionState.Paused || ExecutionState == ExecutionState.Stopped) break; 259 Optimizer.Prepare(); 260 } 261 } 262 public async Task StartAsync() { await StartAsync(CancellationToken.None); } 256 263 public async Task StartAsync(CancellationToken cancellationToken) { 257 this.cancellationToken = cancellationToken; 258 signaler.Reset(); 259 await Task.Run(async () => { 260 if ((ExecutionState != ExecutionState.Prepared) && (ExecutionState != ExecutionState.Paused)) 261 throw new InvalidOperationException(string.Format("Start not allowed in execution state \"{0}\".", ExecutionState)); 262 if (Optimizer == null) return; 263 batchRunAction = BatchRunAction.Start; 264 if (Optimizer.ExecutionState == ExecutionState.Stopped) Optimizer.Prepare(); 265 // a race-condition may occur when the optimizer has changed the state by itself in the meantime 266 try { await Optimizer.StartAsync(cancellationToken); } 267 catch (InvalidOperationException) { } 268 signaler.WaitOne(); 269 }, cancellationToken); 264 await Task.Factory.StartNew((ct) => Start((CancellationToken)ct), cancellationToken, cancellationToken); 270 265 } 271 266 public void Pause() { … … 276 271 if (Optimizer.ExecutionState != ExecutionState.Started) return; 277 272 // a race-condition may occur when the optimizer has changed the state by itself in the meantime 278 try { Optimizer.Pause(); } 279 catch (InvalidOperationException) { } 273 try { Optimizer.Pause(); } catch (InvalidOperationException) { } 280 274 } 281 275 public void Stop() { … … 289 283 } 290 284 // a race-condition may occur when the optimizer has changed the state by itself in the meantime 291 try { Optimizer.Stop(); } 292 catch (InvalidOperationException) { } 285 try { Optimizer.Stop(); } catch (InvalidOperationException) { } 293 286 } 294 287 … … 342 335 batchRunAction = BatchRunAction.None; 343 336 ExecutionState = ExecutionState.Paused; 344 signaler.Set();345 337 EventHandler handler = Paused; 346 338 if (handler != null) handler(this, EventArgs.Empty); … … 350 342 batchRunAction = BatchRunAction.None; 351 343 ExecutionState = ExecutionState.Stopped; 352 signaler.Set();353 344 EventHandler handler = Stopped; 354 345 if (handler != null) handler(this, EventArgs.Empty); … … 413 404 else if (repetitionsCounter >= repetitions) OnStopped(); 414 405 else if (batchRunAction == BatchRunAction.Pause) OnPaused(); 415 else if (batchRunAction == BatchRunAction.Start) { 416 Optimizer.Prepare(); 417 Optimizer.StartAsync(cancellationToken); 418 } else if (executionState == ExecutionState.Started) { 406 else if (batchRunAction == BatchRunAction.Start) return; 407 else if (executionState == ExecutionState.Started) { 419 408 // if the batch run hasn't been started but the inner optimizer was run then pause 420 409 OnPaused(); -
branches/Async/HeuristicLab.Optimization/3.3/MetaOptimizers/Experiment.cs
r13354 r15065 39 39 [StorableClass] 40 40 public sealed class Experiment : NamedItem, IOptimizer, IStorableContent { 41 private readonly ManualResetEvent signaler = new ManualResetEvent(true);42 private CancellationToken cancellationToken;43 44 41 public string Filename { get; set; } 45 42 … … 185 182 foreach (IOptimizer optimizer in Optimizers.Where(x => x.ExecutionState != ExecutionState.Started)) { 186 183 // a race-condition may occur when the optimizer has changed the state by itself in the meantime 187 try { optimizer.Prepare(clearRuns); } 188 catch (InvalidOperationException) { } 184 try { optimizer.Prepare(clearRuns); } catch (InvalidOperationException) { } 189 185 } 190 186 } 191 187 public void Start() { 192 StartAsync().Wait(); 193 } 194 public async Task StartAsync() { 195 await StartAsync(CancellationToken.None); 196 } 188 Start(CancellationToken.None); 189 } 190 public void Start(CancellationToken cancellationToken) { 191 if ((ExecutionState != ExecutionState.Prepared) && (ExecutionState != ExecutionState.Paused)) 192 throw new InvalidOperationException(string.Format("Start not allowed in execution state \"{0}\".", ExecutionState)); 193 if (Optimizers.Count == 0) return; 194 195 experimentStarted = true; 196 experimentStopped = false; 197 IOptimizer optimizer; 198 while ((optimizer = Optimizers.FirstOrDefault(x => (x.ExecutionState == ExecutionState.Prepared) || (x.ExecutionState == ExecutionState.Paused))) != null) { 199 // a race-condition may occur when the optimizer has changed the state by itself in the meantime 200 try { optimizer.Start(cancellationToken); } catch (InvalidOperationException) { } 201 if (ExecutionState == ExecutionState.Paused || ExecutionState == ExecutionState.Stopped) break; 202 } 203 } 204 public async Task StartAsync() { await StartAsync(CancellationToken.None); } 197 205 public async Task StartAsync(CancellationToken cancellationToken) { 198 this.cancellationToken = cancellationToken; 199 signaler.Reset(); 200 await Task.Run(async () => { 201 if ((ExecutionState != ExecutionState.Prepared) && (ExecutionState != ExecutionState.Paused)) 202 throw new InvalidOperationException(string.Format("Start not allowed in execution state \"{0}\".", ExecutionState)); 203 if (Optimizers.Count == 0) return; 204 205 experimentStarted = true; 206 experimentStopped = false; 207 IOptimizer optimizer = Optimizers.FirstOrDefault(x => (x.ExecutionState == ExecutionState.Prepared) || (x.ExecutionState == ExecutionState.Paused)); 208 if (optimizer != null) { 209 // a race-condition may occur when the optimizer has changed the state by itself in the meantime 210 try { await optimizer.StartAsync(cancellationToken); } 211 catch (InvalidOperationException) { } 212 } 213 signaler.WaitOne(); 214 }, cancellationToken); 206 await Task.Factory.StartNew((ct) => Start((CancellationToken)ct), cancellationToken, cancellationToken); 215 207 } 216 208 public void Pause() { … … 223 215 foreach (IOptimizer optimizer in Optimizers.Where(x => x.ExecutionState == ExecutionState.Started)) { 224 216 // a race-condition may occur when the optimizer has changed the state by itself in the meantime 225 try { optimizer.Pause(); } 226 catch (InvalidOperationException) { } 217 try { optimizer.Pause(); } catch (InvalidOperationException) { } 227 218 } 228 219 } … … 237 228 foreach (var optimizer in Optimizers.Where(x => (x.ExecutionState == ExecutionState.Started) || (x.ExecutionState == ExecutionState.Paused))) { 238 229 // a race-condition may occur when the optimizer has changed the state by itself in the meantime 239 try { optimizer.Stop(); } 240 catch (InvalidOperationException) { } 230 try { optimizer.Stop(); } catch (InvalidOperationException) { } 241 231 } 242 232 } else { … … 276 266 private void OnPaused() { 277 267 ExecutionState = ExecutionState.Paused; 278 signaler.Set();279 268 EventHandler handler = Paused; 280 269 if (handler != null) handler(this, EventArgs.Empty); … … 283 272 private void OnStopped() { 284 273 ExecutionState = ExecutionState.Stopped; 285 signaler.Set();286 274 EventHandler handler = Stopped; 287 275 if (handler != null) handler(this, EventArgs.Empty); … … 374 362 try { 375 363 ExecutionTime = Optimizers.Aggregate(TimeSpan.Zero, (t, o) => t + o.ExecutionTime); 376 } 377 finally { 364 } finally { 378 365 Monitor.Exit(locker); 379 366 } … … 396 383 if (Optimizers.All(x => (x.ExecutionState == ExecutionState.Stopped) || (x.ExecutionState == ExecutionState.Prepared))) OnStopped(); 397 384 } else { 398 if (experimentStarted && Optimizers.Any(x => (x.ExecutionState == ExecutionState.Prepared) || (x.ExecutionState == ExecutionState.Paused))) { 399 Optimizers.First(x => (x.ExecutionState == ExecutionState.Prepared) || (x.ExecutionState == ExecutionState.Paused)).StartAsync(cancellationToken); 400 } else if (Optimizers.All(x => x.ExecutionState == ExecutionState.Stopped)) OnStopped(); 385 if (experimentStarted && Optimizers.Any(x => (x.ExecutionState == ExecutionState.Prepared) || (x.ExecutionState == ExecutionState.Paused))) return; 386 else if (Optimizers.All(x => x.ExecutionState == ExecutionState.Stopped)) OnStopped(); 401 387 else if (Optimizers.Any(x => (x.ExecutionState == ExecutionState.Prepared) || (x.ExecutionState == ExecutionState.Paused)) && Optimizers.All(o => o.ExecutionState != ExecutionState.Started)) OnPaused(); 402 388 } -
branches/Async/HeuristicLab.Optimization/3.3/MetaOptimizers/TimeLimitRun.cs
r13354 r15065 41 41 [StorableClass] 42 42 public sealed class TimeLimitRun : NamedItem, IOptimizer, IStorableContent, INotifyPropertyChanged { 43 private readonly ManualResetEvent signaler = new ManualResetEvent(true);44 45 43 public string Filename { get; set; } 46 44 … … 241 239 } 242 240 public void Start() { 243 StartAsync().Wait(); 244 } 245 public async Task StartAsync() { 246 await StartAsync(CancellationToken.None); 247 } 241 Start(CancellationToken.None); 242 } 243 public void Start(CancellationToken cancellationToken) { 244 Algorithm.Start(cancellationToken); 245 } 246 public async Task StartAsync() { await StartAsync(CancellationToken.None); } 248 247 public async Task StartAsync(CancellationToken cancellationToken) { 249 signaler.Reset(); 250 await Task.Run(async () => { 251 await Algorithm.StartAsync(cancellationToken); 252 signaler.WaitOne(); 253 }, cancellationToken); 248 await Task.Factory.StartNew((ct) => Start((CancellationToken)ct), cancellationToken, cancellationToken); 254 249 } 255 250 public void Pause() { … … 295 290 public event EventHandler Paused; 296 291 private void OnPaused() { 297 if (!pausedForSnapshot && !pausedForTermination) signaler.Set();298 292 var handler = Paused; 299 293 if (handler != null) handler(this, EventArgs.Empty); … … 301 295 public event EventHandler Stopped; 302 296 private void OnStopped() { 303 signaler.Set();304 297 var handler = Stopped; 305 298 if (handler != null) handler(this, EventArgs.Empty); … … 351 344 private void Algorithm_Paused(object sender, EventArgs e) { 352 345 var action = pausedForTermination ? ExecutionState.Stopped : (pausedForSnapshot ? ExecutionState.Started : ExecutionState.Paused); 353 bool pausedByLimit = pausedForSnapshot || pausedForTermination;354 if (pausedByLimit) {346 if (pausedForSnapshot || pausedForTermination) { 347 pausedForSnapshot = pausedForTermination = false; 355 348 MakeSnapshot(); 356 349 FindNextSnapshotTimeIndex(ExecutionTime); 357 350 } 358 351 OnPaused(); 359 if (pausedByLimit) pausedForSnapshot = pausedForTermination = false; 360 if (action == ExecutionState.Started) Algorithm.StartAsync(); 352 if (action == ExecutionState.Started) Algorithm.Start(); 361 353 else if (action == ExecutionState.Stopped) Algorithm.Stop(); 362 354 } -
branches/Async/HeuristicLab.Problems.QuadraticAssignment.Algorithms/3.3/RobustTabooSearch.cs
r13349 r15065 23 23 using System.Linq; 24 24 using System.Threading; 25 using System.Threading.Tasks;26 25 using HeuristicLab.Analysis; 27 26 using HeuristicLab.Common; … … 340 339 } 341 340 342 public override async Task StartAsync(CancellationToken cancellationToken) {341 public override void Start(CancellationToken cancellationToken) { 343 342 if (ExecutionState == ExecutionState.Prepared) { 344 343 int dim = Problem.Weights.Rows; … … 352 351 GlobalScope.Variables.Add(new Variable("MoveQualityMatrix", new DoubleMatrix(dim, dim))); 353 352 } 354 await base.StartAsync(cancellationToken);353 base.Start(cancellationToken); 355 354 } 356 355 -
branches/Async/HeuristicLab.Tests/HeuristicLab-3.3/CollectObjectGraphTest.cs
r12012 r15065 24 24 using System.Diagnostics; 25 25 using System.Linq; 26 using System.Threading;27 26 using System.Threading.Tasks; 28 27 using HeuristicLab.Algorithms.GeneticAlgorithm; … … 112 111 algs.Add(ga); 113 112 114 var cancellationTokenSource = new CancellationTokenSource(); 115 ga.StartSync(cancellationTokenSource.Token); 113 ga.Start(); 116 114 sw.Stop(); 117 115 TestContext.WriteLine("{0}: {1} ", i, sw.Elapsed); … … 144 142 var sw = new Stopwatch(); 145 143 sw.Start(); 146 ga.Start Sync(new CancellationToken());144 ga.Start(); 147 145 sw.Stop(); 148 146 Console.WriteLine("{0}; Objects after execution: {1}", ga.Name, ga.GetObjectGraphObjects().Count()); -
branches/Async/HeuristicLab.Tests/HeuristicLab-3.3/GeneticAlgorithmTest.cs
r12012 r15065 21 21 22 22 using System; 23 using System.Threading;24 23 using HeuristicLab.Algorithms.GeneticAlgorithm; 25 24 using HeuristicLab.Common; … … 39 38 } 40 39 41 private EventWaitHandle trigger = new AutoResetEvent(false);42 40 private Exception ex; 43 41 … … 49 47 GeneticAlgorithm ga = (GeneticAlgorithm)XmlParser.Deserialize(@"Test Resources\GA_TSP.hl"); 50 48 ga.ExceptionOccurred += new EventHandler<EventArgs<Exception>>(ga_ExceptionOccurred); 51 ga.Stopped += new EventHandler(ga_Stopped);52 49 ga.SetSeedRandomly.Value = false; 53 50 ga.Seed.Value = 0; … … 55 52 ga.Prepare(); 56 53 ga.Start(); 57 trigger.WaitOne();58 54 if (ex != null) throw ex; 59 55 … … 80 76 ex = e.Value; 81 77 } 82 83 private void ga_Stopped(object sender, EventArgs e) {84 trigger.Set();85 }86 78 } 87 79 } -
branches/Async/HeuristicLab.Tests/HeuristicLab.Algorithms.DataAnalysis-3.4/GaussianProcessRegressionTest.cs
r12012 r15065 22 22 using System; 23 23 using System.Linq; 24 using System.Threading;25 24 using HeuristicLab.Common; 26 25 using HeuristicLab.Problems.DataAnalysis; … … 39 38 } 40 39 41 private EventWaitHandle trigger = new AutoResetEvent(false);42 40 private Exception ex; 43 41 … … 65 63 66 64 alg.ExceptionOccurred += new EventHandler<EventArgs<Exception>>(cv_ExceptionOccurred); 67 alg.Stopped += new EventHandler(cv_Stopped);68 65 69 66 alg.Prepare(); 70 67 alg.Start(); 71 trigger.WaitOne();72 68 if (ex != null) throw ex; 73 69 … … 78 74 ex = e.Value; 79 75 } 80 81 private void cv_Stopped(object sender, EventArgs e) {82 trigger.Set();83 }84 76 } 85 77 } -
branches/Async/HeuristicLab.Tests/HeuristicLab.Algorithms.DataAnalysis-3.4/GradientBoostingTest.cs
r13157 r15065 1 1 using System; 2 2 using System.Linq; 3 using System.Threading;4 3 using HeuristicLab.Data; 5 using HeuristicLab.Optimization;6 4 using HeuristicLab.Problems.DataAnalysis; 7 5 using Microsoft.VisualStudio.TestTools.UnitTesting; … … 182 180 #endregion 183 181 184 RunAlgorithm(gbt);182 gbt.Start(); 185 183 186 184 Console.WriteLine(gbt.ExecutionTime); … … 210 208 #endregion 211 209 212 RunAlgorithm(gbt);210 gbt.Start(); 213 211 214 212 Console.WriteLine(gbt.ExecutionTime); … … 238 236 #endregion 239 237 240 RunAlgorithm(gbt);238 gbt.Start(); 241 239 242 240 Console.WriteLine(gbt.ExecutionTime); 243 241 Assert.AreEqual(0.061954221604374943, ((DoubleValue)gbt.Results["Loss (train)"].Value).Value, 1E-6); 244 242 Assert.AreEqual(0.06316303473499961, ((DoubleValue)gbt.Results["Loss (test)"].Value).Value, 1E-6); 245 }246 247 // same as in SamplesUtil248 private void RunAlgorithm(IAlgorithm a) {249 var trigger = new EventWaitHandle(false, EventResetMode.ManualReset);250 Exception ex = null;251 a.Stopped += (src, e) => { trigger.Set(); };252 a.ExceptionOccurred += (src, e) => { ex = e.Value; trigger.Set(); };253 a.Prepare();254 a.Start();255 trigger.WaitOne();256 257 Assert.AreEqual(ex, null);258 243 } 259 244 -
branches/Async/HeuristicLab.Tests/HeuristicLab.Algorithms.DataAnalysis-3.4/SupportVectorMachineTest.cs
r12012 r15065 23 23 using System.Collections.Generic; 24 24 using System.Linq; 25 using System.Threading;26 25 using HeuristicLab.Algorithms.DataAnalysis; 27 26 using HeuristicLab.Common; … … 50 49 } 51 50 52 private EventWaitHandle trigger = new AutoResetEvent(false);53 51 private Exception ex; 54 52 … … 71 69 72 70 cv.ExceptionOccurred += new EventHandler<EventArgs<Exception>>(cv_ExceptionOccurred); 73 cv.Stopped += new EventHandler(cv_Stopped);74 71 75 72 cv.Prepare(); 76 73 cv.Start(); 77 trigger.WaitOne();78 74 if (ex != null) throw ex; 79 75 … … 102 98 ex = e.Value; 103 99 } 104 105 private void cv_Stopped(object sender, EventArgs e) {106 trigger.Set();107 }108 100 } 109 101 } -
branches/Async/HeuristicLab.Tests/HeuristicLab.Scripting-3.3/Script Sources/GUIAutomationScriptSource.cs
r11789 r15065 1 using System; 2 using System.Linq; 3 using System.Threading; 1 using System.Linq; 4 2 using System.Windows.Forms; 5 3 6 4 using HeuristicLab.Algorithms.GeneticAlgorithm; 7 using HeuristicLab.Core;8 5 using HeuristicLab.MainForm; 9 6 using HeuristicLab.MainForm.WindowsForms; … … 13 10 14 11 public class GUIAutomationScript : HeuristicLab.Scripting.CSharpScriptBase { 15 readonly ManualResetEvent mutex = new ManualResetEvent(false);16 17 12 public override void Main() { 18 13 var ga = new GeneticAlgorithm { … … 27 22 ga.PopulationSize.Value *= 2; 28 23 } 29 30 experiment.ExecutionStateChanged += OnExecutionStateChanged;31 24 experiment.Start(); 32 mutex.WaitOne();33 25 34 26 vars.experiment = experiment; … … 39 31 bubbleChart.Controls.OfType<ComboBox>().Single(x => x.Name == "xAxisComboBox").SelectedItem = "PopulationSize"; 40 32 } 41 42 private void OnExecutionStateChanged(object sender, EventArgs e) {43 if (((IExecutable)sender).ExecutionState == ExecutionState.Stopped)44 mutex.Set();45 }46 33 } -
branches/Async/HeuristicLab.Tests/HeuristicLab.Tests.csproj
r13266 r15065 428 428 <ItemGroup> 429 429 <Compile Include="AssemblyInitializer.cs" /> 430 <Compile Include="HeuristicLab-3.3\AlgorithmExtensions.cs" />431 430 <Compile Include="HeuristicLab-3.3\CloningConstructorTest.cs" /> 432 431 <Compile Include="HeuristicLab-3.3\CollectObjectGraphTest.cs" />
Note: See TracChangeset
for help on using the changeset viewer.