DotNetWorkQueue.Queue.MessageProcessingAsync.DoTry C# (CSharp) Method

DoTry() private method

Tries the process a new incoming message.
private DoTry ( IMessageContext context ) : Task
context IMessageContext The context.
return Task
        private async Task DoTry(IMessageContext context)
        {
            var receiveMessage = _receiveMessages.Create();

            //this call must block; otherwise, the limitations enforced by the task scheduler will be ignored
            //calling the async method here may result in hundreds of de-queues at once, instead of the N set in the configuration
            var transportMessage = receiveMessage.ReceiveMessage(context);

            if (transportMessage == null)
            {
                //delay processing since we have no messages to process
                if (!_idle)
                {
                    Idle(this, EventArgs.Empty);
                    _idle = true;
                }
                _noMessageToProcessBackoffHelper.Value.Wait();
                return;
            }

            //reset the back off counter - we have a message to process, so the wait times are now reset
            _noMessageToProcessBackoffHelper.Value.Reset();
            //we are no longer idle
            if (_idle)
            {
                NotIdle(this, EventArgs.Empty);
                _idle = false;
            }

            //process the message
            await _processMessage.Handle(context, transportMessage).ConfigureAwait(false);
        }
    }