public void Run() { this.shouldStop = false; log.Info("PlcReader Run"); var numErrors = 0; var sleepTime = TimeFn.ExponentialTimeoutFn(numErrors,this.poolInvertalMs); while (!this.shouldStop) { try { this.Connect(); sleepTime = TimeFn.ExponentialTimeoutFn(numErrors,this.poolInvertalMs); Thread.Sleep(sleepTime); log.Debug("Updating Variables"); this.Update(); log.Debug("Updated Variables"); numErrors = 0; } catch (Exception ex) { numErrors += 1; sleepTime = TimeFn.ExponentialTimeoutFn(numErrors,this.poolInvertalMs); log.Error(ex); log.Info($"Retyring next time in {sleepTime / 1000} seconds"); } } }
public void Run() { this.shouldStop = false; log.Info("MetricsReader Run"); const int MAX_ERRORS = 10; var numErrors = 0; int sleepTime = TimeFn.ExponentialTimeoutFn(numErrors, this.poolInterval); while (!this.shouldStop || numErrors < MAX_ERRORS) { try { sleepTime = TimeFn.ExponentialTimeoutFn(numErrors, this.poolInterval); Thread.Sleep(sleepTime); log.Debug("Updating Variables"); this.updateVariableStates(); log.Debug("Updated Variables"); var eventArgs = new VariablesUpdatedEventArgs { variables = this.variableState.Values }; this.VariablesUpdated.Invoke(this, eventArgs); numErrors = 0; } catch (Exception ex) { numErrors += 1; sleepTime = TimeFn.ExponentialTimeoutFn(numErrors, this.poolInterval); log.Error(ex); log.Info($"Retyring next time in {sleepTime/1000} seconds"); } } if (numErrors >= MAX_ERRORS) { throw new Exception($"Metrics Reader reached {MAX_ERRORS} consecutive errors .... Giving up"); } }