private void Execute(CancellationToken token) { int lastExecutedTicks = System.Environment.TickCount; int benchmarkCount = _activeBenchmarks.Count; BenchmarkInstance onlyBenchmark = benchmarkCount == 1 ? _activeBenchmarks[0] : null; try { while (_running && !token.IsCancellationRequested) { if (_configuration.MeasurementType == MeasurementType.Nominal) { double ticksToNextTransaction = _ticksPerTransaction - (System.Environment.TickCount - lastExecutedTicks); // Wait to ensure nominal transaction rate if (ticksToNextTransaction > 0) { Thread.Sleep((int)ticksToNextTransaction); } } var benchmark = onlyBenchmark ?? ChooseBenchmarkProportionally(); if (benchmark != null) { ExecuteBenchmark(benchmark); lastExecutedTicks = System.Environment.TickCount; _aggregator.IncrementCounter(1, lastExecutedTicks); } else { Thread.Sleep(500); } } } catch (OperationCanceledException) { // Ignore the exception... } }
public void IncrementCounter() { _aggregator.IncrementCounter(1); }