- 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/MetaOptimizers/BatchRun.cs
r14185 r15287 23 23 using System.Collections.Generic; 24 24 using System.Drawing; 25 using System.Threading; 26 using System.Threading.Tasks; 25 27 using HeuristicLab.Collections; 26 28 using HeuristicLab.Common; … … 237 239 batchRunAction = BatchRunAction.Prepare; 238 240 // a race-condition may occur when the optimizer has changed the state by itself in the meantime 239 try { Optimizer.Prepare(clearRuns); } 240 catch (InvalidOperationException) { } 241 try { Optimizer.Prepare(clearRuns); } catch (InvalidOperationException) { } 241 242 } else { 242 243 ExecutionState = ExecutionState.Stopped; … … 244 245 } 245 246 public void Start() { 247 Start(CancellationToken.None); 248 } 249 public void Start(CancellationToken cancellationToken) { 246 250 if ((ExecutionState != ExecutionState.Prepared) && (ExecutionState != ExecutionState.Paused)) 247 251 throw new InvalidOperationException(string.Format("Start not allowed in execution state \"{0}\".", ExecutionState)); … … 249 253 batchRunAction = BatchRunAction.Start; 250 254 if (Optimizer.ExecutionState == ExecutionState.Stopped) Optimizer.Prepare(); 251 // a race-condition may occur when the optimizer has changed the state by itself in the meantime 252 try { Optimizer.Start(); } 253 catch (InvalidOperationException) { } 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); } 263 public async Task StartAsync(CancellationToken cancellationToken) { 264 await AsyncHelper.DoAsync(Start, cancellationToken); 254 265 } 255 266 public void Pause() { … … 260 271 if (Optimizer.ExecutionState != ExecutionState.Started) return; 261 272 // a race-condition may occur when the optimizer has changed the state by itself in the meantime 262 try { Optimizer.Pause(); } 263 catch (InvalidOperationException) { } 273 try { Optimizer.Pause(); } catch (InvalidOperationException) { } 264 274 } 265 275 public void Stop() { … … 273 283 } 274 284 // a race-condition may occur when the optimizer has changed the state by itself in the meantime 275 try { Optimizer.Stop(); } 276 catch (InvalidOperationException) { } 285 try { Optimizer.Stop(); } catch (InvalidOperationException) { } 277 286 } 278 287 … … 395 404 else if (repetitionsCounter >= repetitions) OnStopped(); 396 405 else if (batchRunAction == BatchRunAction.Pause) OnPaused(); 397 else if (batchRunAction == BatchRunAction.Start) { 398 Optimizer.Prepare(); 399 Optimizer.Start(); 400 } else if (executionState == ExecutionState.Started) { 406 else if (batchRunAction == BatchRunAction.Start) return; 407 else if (executionState == ExecutionState.Started) { 401 408 // if the batch run hasn't been started but the inner optimizer was run then pause 402 409 OnPaused();
Note: See TracChangeset
for help on using the changeset viewer.