protected void ScheduleItem(ScheduledTransmitterItem <TItem> transmitterItem) { lock (_timer) { StoreItem(transmitterItem); if (IsNearestDateChanged()) { TrySendItems(); } } }
private async void StoreItem(ScheduledTransmitterItem <TItem> transmitterItem) { if (transmitterItem.StopSchedule) { _itemsCollection.Remove(transmitterItem.Item); } else { var roundedDate = GetRoundedDate(transmitterItem.ScheduleDate); if (roundedDate <= _dateTimeProvider.Now) { await SendAsync(transmitterItem.Item); } else { _itemsCollection.Add(transmitterItem.Item, roundedDate); } } }