/// <summary> /// Starts listening for messages on the configured Service Bus Queue. /// </summary> protected override void ListenForMessages() { ThreadStart ts = async() => { WriteLog($"Service Bus Communication Listnener now listening for messages."); while (!StopProcessingMessageToken.IsCancellationRequested) { var messages = ServiceBusClient.ReceiveBatch(MessageBatchSize, ServerTimeout).ToArray(); if (messages.Length == 0) { continue; } var tokens = BatchReceiver.AutoComplete ? messages.Select(m => m.LockToken).ToArray() : null; await ProcessMessagesAsync(messages, null); if (BatchReceiver.AutoComplete) { await ServiceBusClient.CompleteBatchAsync(tokens); } } }; StartBackgroundThread(ts); }