Exemplo n.º 1
0
        private void ReceiveNonTryMessages(TimeSpan channelTimeout, TimeSpan messageTimeout)
        {
            IChannelListener inputChannelParentListener;
            IInputChannel    inputChannel = this.RetrieveAsyncChannel(this.endpoint, channelTimeout, out inputChannelParentListener);

            inputChannel.Open();

            IAsyncResult[] resultArray = new IAsyncResult[MessageCount];
            try
            {
                for (int i = 0; i < MessageCount; i++)
                {
                    resultArray[i] = inputChannel.BeginReceive(messageTimeout, null, null);
                }

                for (int j = 0; j < MessageCount; j++)
                {
                    inputChannel.EndReceive(resultArray[j]);
                }
            }
            finally
            {
                IAsyncResult channelCloseResult = inputChannel.BeginClose(channelTimeout, null, null);
                Thread.Sleep(TimeSpan.FromMilliseconds(50.0)); // Dummy work
                inputChannel.EndClose(channelCloseResult);

                // Asynchronous listener close has not been implemented.
                ////IAsyncResult listenerCloseResult = inputChannelParentListener.BeginClose(channelTimeout, null, null);
                ////Thread.Sleep(TimeSpan.FromMilliseconds(50.0)); // Dummy work
                ////inputChannelParentListener.EndClose(listenerCloseResult);

                inputChannelParentListener.Close();
            }
        }