public async Task <IEnumerable <IBatchContainer> > GetQueueMessagesAsync() { try { var task = queue.GetQueueMessages(); outstandingTask = task; CloudQueueMessage[] messages = (await task).ToArray(); if (!messages.Any()) { return(Enumerable.Empty <IBatchContainer>()); } AzureQueueBatchContainer[] azureQueueMessages = messages .Select(msg => AzureQueueBatchContainer.FromCloudQueueMessage(msg, lastReadMessage++)).ToArray(); outstandingTask = Task.WhenAll(messages.Select(queue.DeleteQueueMessage)); await outstandingTask; return(azureQueueMessages); } finally { outstandingTask = null; } }
public async Task <IList <IBatchContainer> > GetQueueMessagesAsync(int maxCount) { try { var queueRef = queue; // store direct ref, in case we are somehow asked to shutdown while we are receiving. if (queueRef == null) { return(new List <IBatchContainer>()); } int count = maxCount < 0 || maxCount == QueueAdapterConstants.UNLIMITED_GET_QUEUE_MSG ? CloudQueueMessage.MaxNumberOfMessagesToPeek : Math.Min(maxCount, CloudQueueMessage.MaxNumberOfMessagesToPeek); var task = queueRef.GetQueueMessages(count); outstandingTask = task; IEnumerable <CloudQueueMessage> messages = await task; List <IBatchContainer> azureQueueMessages = messages .Select(msg => (IBatchContainer)AzureQueueBatchContainer.FromCloudQueueMessage(msg, lastReadMessage++)).ToList(); return(azureQueueMessages); } finally { outstandingTask = null; } }
public async Task <IList <IBatchContainer> > GetQueueMessagesAsync(int maxCount) { try { int count = maxCount < 0 || maxCount == QueueAdapterConstants.UNLIMITED_GET_QUEUE_MSG ? CloudQueueMessage.MaxNumberOfMessagesToPeek : Math.Min(maxCount, CloudQueueMessage.MaxNumberOfMessagesToPeek); var task = queue.GetQueueMessages(count); outstandingTask = task; IEnumerable <CloudQueueMessage> messages = await task; List <IBatchContainer> azureQueueMessages = messages .Select(msg => (IBatchContainer)AzureQueueBatchContainer.FromCloudQueueMessage(msg, lastReadMessage++)).ToList(); if (azureQueueMessages.Count == 0) { return(azureQueueMessages); } outstandingTask = Task.WhenAll(messages.Select(queue.DeleteQueueMessage)); await outstandingTask; return(azureQueueMessages); } finally { outstandingTask = null; } }