Exemplo n.º 1
0
        public override MsmqQueue.ReceiveResult TryReceive(NativeMsmqMessage message, TimeSpan timeout, MsmqTransactionMode transactionMode)
        {
            TimeoutHelper   helper = new TimeoutHelper(timeout);
            MsmqQueueHandle handle = base.GetHandle();

            while (true)
            {
                int error = this.PeekLockCore(handle, (MsmqInputMessage)message, helper.RemainingTime());
                if (error == 0)
                {
                    return(MsmqQueue.ReceiveResult.MessageReceived);
                }
                if (!MsmqQueue.IsReceiveErrorDueToInsufficientBuffer(error))
                {
                    if (error == -1072824293)
                    {
                        return(MsmqQueue.ReceiveResult.Timeout);
                    }
                    if (error == -1072824312)
                    {
                        return(MsmqQueue.ReceiveResult.OperationCancelled);
                    }
                    if (error == -1072824313)
                    {
                        return(MsmqQueue.ReceiveResult.OperationCancelled);
                    }
                    if (MsmqQueue.IsErrorDueToStaleHandle(error))
                    {
                        base.HandleIsStale(handle);
                    }
                    throw DiagnosticUtility.ExceptionUtility.ThrowHelperError(new MsmqException(System.ServiceModel.SR.GetString("MsmqReceiveError", new object[] { MsmqError.GetErrorString(error) }), error));
                }
                message.GrowBuffers();
            }
        }
            private void OnCompletion(int error, bool completedSynchronously)
            {
                Exception exception = null;

                this.receiveResult = MsmqQueue.ReceiveResult.MessageReceived;
                try
                {
                    if (error != 0)
                    {
                        if (error != -1072824293)
                        {
                            if (error != -1072824312)
                            {
                                if (!MsmqQueue.IsReceiveErrorDueToInsufficientBuffer(error))
                                {
                                    if (MsmqQueue.IsErrorDueToStaleHandle(error))
                                    {
                                        this.msmqQueue.HandleIsStale(this.handle);
                                    }
                                    throw DiagnosticUtility.ExceptionUtility.ThrowHelperError(new MsmqException(System.ServiceModel.SR.GetString("MsmqReceiveError", new object[] { MsmqError.GetErrorString(error) }), error));
                                }
                                this.message.Unpin();
                                this.message.GrowBuffers();
                                this.StartReceive(completedSynchronously);
                                return;
                            }
                            this.receiveResult = MsmqQueue.ReceiveResult.OperationCancelled;
                        }
                        else
                        {
                            this.receiveResult = MsmqQueue.ReceiveResult.Timeout;
                        }
                    }
                }
                catch (Exception exception2)
                {
                    if ((exception2 is NullReferenceException) || (exception2 is SEHException))
                    {
                        throw;
                    }
                    exception = exception2;
                }
                this.message.Unpin();
                base.Complete(completedSynchronously, exception);
            }