I'm trying to implement an efficient algorithm for polling queue which can be found at https://gist.github.com/3093080
I can get a batch of messages using the follow code.
var messages = await Task.Factory.FromAsync>(queue.BeginGetMessages, queue.EndGetMessages, settings.DequeueMessageBatchSize, settings.MessageVisibilityTimeout, null, TaskCreationOptions.AttachedToParent);
Once I process this batch message, I would also like to delete all the messages in a batch.
Currently there is now way besides looping through all the messages. This causes multiple transactions rather then one and also requires use to increase the visibility timeout for the message depending on our batch message size just for deleting the messages.
private async static Task DeleteMessages(CloudQueuePollSettings settings, CloudQueue queue, IEnumerable messages)
foreach (var message in messages)
int retryCount = settings.RetryCount;
Exception exception = null;
await Task.Factory.FromAsync(queue.BeginDeleteMessage, queue.EndDeleteMessage, message, null);
catch (Exception ex)
exception = ex;
if (exception != null)
await settings.OnError(queue, exception, message, retryCount == 0);
} while (retryCount >= 0);
I would recommend for a BeginDeleteMessages and EndDeleteMessages methods that would allow us to pass an IEnumerable.
But first the queue service api needs to support deleting batch of messages.
Please recreate in https://github.com/Azure/azure-storage-net/ if still relevant.