private async Task ExecuteToggle(ToggleAction action) { if (!Toggles.ContainsKey(action.TinBotToggle)) { return; } for (int i = 0; i < action.Repeat; i++) { if (action.TimeOn > 0) { var t = _body.SerialOut.SetValue(Toggles[action.TinBotToggle], true); await Task.WhenAll(t, Task.Delay(action.TimeOn)); } if (action.TimeOff > 0) { var t = _body.SerialOut.SetValue(Toggles[action.TinBotToggle], false); await Task.WhenAll(t, Task.Delay(action.TimeOff)); } } }