I am trying to isolate messages in Azure Queues asynchronously as follows:
private async Task EnqueueItemsAsync(IEnumerable<string> messages) { var tasks = messages.Select(msg => _queue.AddMessageAsync(new CloudQueueMessage(msg), null, null, null, null)); await Task.WhenAll(tasks); }
If I understood correctly, this says: "Run enqueuing one item after another, not expecting them to be sent, save the link for each task, and then wait until everyone is sent."
This code works fine in most cases, but for a large number of elements (5000), it starts enqueuing and then throws a timeout exception (after the value is set to ~ 3500 elements).
I solved this, expecting everyone to finish before continuing with the next
private async Task EnqueueItemsAsync(IEnumerable<string> messages) { foreach (var message in messages) { await _queue.AddMessageAsync(new CloudQueueMessage(message), null, null, null, null); } }
Can anyone explain why this happened?
An exception:
System.AggregateException that covers many of these exceptions: Microsoft.WindowsAzure.Storage.Core.Util.AsyncExtensions.<>c__DisplayClass4.<CreateCallbackVoid>b__3(IAsyncResult ar) Request Information RequestID: RequestDate: StatusMessage: <--- ---> (Internal exception # 1) Microsoft.WindowsAzure.Storage.StorageException: The client could not complete the operation within the specified timeout. ---> System.TimeoutException: the client could not complete the operation within the specified timeout. --- End of internal check of the exception stack --- Microsoft.WindowsAzure.Storage.Core.Executor.Executor.EndExecuteAsync [T] (IAsyncResult result) `.
source share