protected override bool DoPoll()
        {
            IMessage message = _source.Receive();

            if (message != null)
            {
                return(_channelTemplate.Send(message, _outputChannel));
            }
            return(false);
        }
        public Message Receive(TimeSpan timeout)
        {
            TimeoutHelper timeoutHelper = new TimeoutHelper(timeout);

            // If timeout == TimeSpan.MaxValue, then we want to pass Timeout.Infinite as
            // SemaphoreSlim doesn't accept timeouts > Int32.MaxValue.
            // Using TimeoutHelper.RemainingTime() would yield a value less than TimeSpan.MaxValue
            // and would result in the value Int32.MaxValue so we must use the original timeout specified.
            if (!_sourceLock.Wait(TimeoutHelper.ToMilliseconds(timeout)))
            {
                throw DiagnosticUtility.ExceptionUtility.ThrowHelperError(
                          new TimeoutException(SR.Format(SR.ReceiveTimedOut2, timeout),
                                               TimeoutHelper.CreateEnterTimedOutException(timeout)));
            }

            try
            {
                return(_source.Receive(timeoutHelper.RemainingTime()));
            }
            finally
            {
                _sourceLock.Release();
            }
        }