private void OnMessage(IAsyncResult ar) { try { var receivedMessages = _queueClient.EndReceiveBatch(ar); if (cancelRequested) { return; } foreach (var receivedMessage in receivedMessages) { _tryProcessMessage(receivedMessage); } } catch (MessagingEntityDisabledException) { if (cancelRequested) { return; } Thread.Sleep(TimeSpan.FromSeconds(BackoffTimeInSeconds)); } catch (ServerBusyException) { if (cancelRequested) { return; } Thread.Sleep(TimeSpan.FromSeconds(BackoffTimeInSeconds)); } _queueClient.BeginReceiveBatch(BatchSize, TimeSpan.FromSeconds(ServerWaitTime), OnMessage, null); }