public void Update() { _updateStopwatch.Restart(); try { if (commands == null) { commands = new ICommand[OutputCount]; } _outputMediator.LockOutputs(); for (int i = 0; i < OutputCount; i++) { commands[i] = GenerateOutputCommand(Outputs[i]); } ControllerModule.UpdateState(0, commands); } catch (Exception e) { Logging.Error(e, "An error ocuered outputing data for controller {0}", Name); } finally { _outputMediator.UnlockOutputs(); } _updateTimeValue.Set(_updateStopwatch.ElapsedMilliseconds); _updateStopwatch.Stop(); }
public void Update() { _updateStopwatch.Restart(); try { if (commands == null) { commands = new ICommand[OutputCount]; } _outputMediator.LockOutputs(); if (OutputCount > 15000) { Parallel.For(0, OutputCount, _parallelOptions, () => ControllerModule.DataPolicyFactory.CreateDataPolicy(), (x, loopState, dataPolicy) => { var o = Outputs[x].State; commands[x] = o?.Value != null ? dataPolicy.GenerateCommand(o) : null; return(dataPolicy); }, x => { }); //nothing to do but let the datapolicy expire } else { for (int x = 0; x < OutputCount; x++) { var o = Outputs[x].State; commands[x] = o?.Value != null?_dataPolicy.GenerateCommand(o) : null; } } ControllerModule.UpdateState(0, commands); } catch (Exception e) { Logging.Error(e, "An error occurred outputting data for controller {0}", Name); } finally { _outputMediator.UnlockOutputs(); } _updateTimeValue.Set(_updateStopwatch.ElapsedMilliseconds); _updateStopwatch.Stop(); }