public void Start(CancellationToken cancellationToken) { if ((ExecutionState != ExecutionState.Prepared) && (ExecutionState != ExecutionState.Paused)) { throw new InvalidOperationException(string.Format("Start not allowed in execution state \"{0}\".", ExecutionState)); } if (Optimizer == null) { return; } batchRunAction = BatchRunAction.Start; if (Optimizer.ExecutionState == ExecutionState.Stopped) { Optimizer.Prepare(); } for (int i = repetitionsCounter; i < repetitions; i++) { // a race-condition may occur when the optimizer has changed the state by itself in the meantime try { Optimizer.Start(cancellationToken); } catch (InvalidOperationException) { } if (ExecutionState == ExecutionState.Paused || ExecutionState == ExecutionState.Stopped) { break; } Optimizer.Prepare(); if (ExecutionState == ExecutionState.Paused || ExecutionState == ExecutionState.Stopped) { break; } } }
private void OnStopped() { batchRunAction = BatchRunAction.None; ExecutionState = ExecutionState.Stopped; EventHandler handler = Stopped; if (handler != null) { handler(this, EventArgs.Empty); } }
private BatchRun(BatchRun original, Cloner cloner) : base(original, cloner) { executionState = original.executionState; executionTime = original.executionTime; runsExecutionTime = original.runsExecutionTime; optimizer = cloner.Clone(original.optimizer); repetitions = original.repetitions; repetitionsCounter = original.repetitionsCounter; runs = cloner.Clone(original.runs); batchRunAction = original.batchRunAction; Initialize(); }
public void Pause() { if (ExecutionState != ExecutionState.Started) { throw new InvalidOperationException(string.Format("Pause not allowed in execution state \"{0}\".", ExecutionState)); } if (Optimizer == null) { return; } batchRunAction = BatchRunAction.Pause; if (Optimizer.ExecutionState != ExecutionState.Started) { return; } // a race-condition may occur when the optimizer has changed the state by itself in the meantime try { Optimizer.Pause(); } catch (InvalidOperationException) { } catch (NotSupportedException) { } }
public void Stop() { if ((ExecutionState != ExecutionState.Started) && (ExecutionState != ExecutionState.Paused)) { throw new InvalidOperationException(string.Format("Stop not allowed in execution state \"{0}\".", ExecutionState)); } if (Optimizer == null) { return; } batchRunAction = BatchRunAction.Stop; if (Optimizer.ExecutionState != ExecutionState.Started && Optimizer.ExecutionState != ExecutionState.Paused) { OnStopped(); return; } // a race-condition may occur when the optimizer has changed the state by itself in the meantime try { Optimizer.Stop(); } catch (InvalidOperationException) { } }
public void Prepare(bool clearRuns) { if ((ExecutionState != ExecutionState.Prepared) && (ExecutionState != ExecutionState.Paused) && (ExecutionState != ExecutionState.Stopped)) { throw new InvalidOperationException(string.Format("Prepare not allowed in execution state \"{0}\".", ExecutionState)); } if (Optimizer != null) { ExecutionTime = TimeSpan.Zero; RepetitionsCounter = 0; if (clearRuns) { runs.Clear(); } batchRunAction = BatchRunAction.Prepare; // a race-condition may occur when the optimizer has changed the state by itself in the meantime try { Optimizer.Prepare(clearRuns); } catch (InvalidOperationException) { } } else { ExecutionState = ExecutionState.Stopped; } }
private void OnStopped() { batchRunAction = BatchRunAction.None; ExecutionState = ExecutionState.Stopped; EventHandler handler = Stopped; if (handler != null) handler(this, EventArgs.Empty); }
public void Stop() { if ((ExecutionState != ExecutionState.Started) && (ExecutionState != ExecutionState.Paused)) throw new InvalidOperationException(string.Format("Stop not allowed in execution state \"{0}\".", ExecutionState)); if (Optimizer == null) return; batchRunAction = BatchRunAction.Stop; if (Optimizer.ExecutionState != ExecutionState.Started && Optimizer.ExecutionState != ExecutionState.Paused) { OnStopped(); return; } // a race-condition may occur when the optimizer has changed the state by itself in the meantime try { Optimizer.Stop(); } catch (InvalidOperationException) { } }
public void Prepare(bool clearRuns) { if ((ExecutionState != ExecutionState.Prepared) && (ExecutionState != ExecutionState.Paused) && (ExecutionState != ExecutionState.Stopped)) throw new InvalidOperationException(string.Format("Prepare not allowed in execution state \"{0}\".", ExecutionState)); if (Optimizer != null) { ExecutionTime = TimeSpan.Zero; RepetitionsCounter = 0; if (clearRuns) runs.Clear(); batchRunAction = BatchRunAction.Prepare; // a race-condition may occur when the optimizer has changed the state by itself in the meantime try { Optimizer.Prepare(clearRuns); } catch (InvalidOperationException) { } } else { ExecutionState = ExecutionState.Stopped; } }