public static void SendQueuedMessages(Guid batchId) { using (var dataBinding = new MessageDataAccessor()) { List<MessageEntity> list = new List<MessageEntity>(); foreach (var message in dataBinding.GetQueuedMessages(batchId)) { list.Add(new MessageEntity() { NumberTo = message.Number, Text = message.Text, OriginId = message.OriginId, UniqueId = message.UniqueId }); } SendSMS(list); // if sent successfully we remove the item from the queue foreach (MessageEntity message in list) { dataBinding.RemoveSentMessages(message.UniqueId); } } }