private static void TimerCallback(object state)
 {
     DuplexRequestBindingElement.DuplexRequestSessionChannel.DuplexCorrelationAsyncResult duplexCorrelationAsyncResult = (DuplexRequestBindingElement.DuplexRequestSessionChannel.DuplexCorrelationAsyncResult)state;
     if (duplexCorrelationAsyncResult.parent.inflightRequests.TryRemove(duplexCorrelationAsyncResult.RequestMessageId, out duplexCorrelationAsyncResult))
     {
         string   timeoutOnRequest = Resources.TimeoutOnRequest;
         object[] originalTimeout  = new object[] { duplexCorrelationAsyncResult.OriginalTimeout };
         string   str = SRClient.TrackableExceptionMessageFormat(Microsoft.ServiceBus.SR.GetString(timeoutOnRequest, originalTimeout), duplexCorrelationAsyncResult.CreateClientTrackingExceptionInfo());
         MessagingClientEtwProvider.TraceClient(() => MessagingClientEtwProvider.Provider.EventWriteLogOperationWarning("DuplexMessageCorrelation.TimerCallback", string.Format(CultureInfo.InvariantCulture, "In IO Thread Time callback , removing Request with Message Id:{0} and terminating the request with error: {1}", new object[] { duplexCorrelationAsyncResult.RequestMessageId.ToString(), str })));
         duplexCorrelationAsyncResult.TryComplete(false, new TimeoutException(str));
     }
 }
            private bool HandleMessageReceived(IAsyncResult result)
            {
                Exception exception = null;

                DuplexRequestBindingElement.DuplexRequestSessionChannel.DuplexCorrelationAsyncResult duplexCorrelationAsyncResult = null;
                try
                {
                    Message message = null;
                    if (this.innerChannel.EndTryReceive(result, out message))
                    {
                        if (message != null)
                        {
                            UniqueId relatesTo = message.Headers.RelatesTo;
                            if (!this.inflightRequests.TryRemove(relatesTo, out duplexCorrelationAsyncResult))
                            {
                                MessagingClientEtwProvider.TraceClient(() => {
                                });
                            }
                            else
                            {
                                duplexCorrelationAsyncResult.ReplyMessage = message;
                                this.ThrowIfFaultMessage(duplexCorrelationAsyncResult.ReplyMessage);
                            }
                        }
                        else if (base.State != CommunicationState.Opened)
                        {
                            this.serverShutdownEvent.Set();
                            return(false);
                        }
                        else
                        {
                            MessagingClientEtwProvider.TraceClient(() => MessagingClientEtwProvider.Provider.EventWriteRuntimeChannelFaulting(this.innerChannel.GetType().Name, this.innerChannel.LocalAddress.Uri.AbsoluteUri, this.innerChannel.RemoteAddress.Uri.AbsoluteUri, this.innerChannel.Via.AbsoluteUri, this.innerChannel.Session.Id, "HandleMessageReceived: Received null message."));
                            base.Fault();
                        }
                    }
                }
                catch (Exception exception2)
                {
                    Exception exception1 = exception2;
                    if (Fx.IsFatal(exception1))
                    {
                        throw;
                    }
                    if (duplexCorrelationAsyncResult == null && (!base.IsDisposed || !(exception1 is CommunicationObjectAbortedException)))
                    {
                        MessagingClientEtwProvider.TraceClient(() => MessagingClientEtwProvider.Provider.EventWriteRuntimeChannelFaulting(this.innerChannel.GetType().Name, this.innerChannel.LocalAddress.Uri.AbsoluteUri, this.innerChannel.RemoteAddress.Uri.AbsoluteUri, this.innerChannel.Via.AbsoluteUri, this.innerChannel.Session.Id, string.Concat("HandleMessageReceived: ", exception1.ToString())));
                        base.Fault();
                    }
                    exception = exception1;
                }
                if (duplexCorrelationAsyncResult != null)
                {
                    ActionItem.Schedule((object s) => duplexCorrelationAsyncResult.TryComplete(false, exception), null);
                }
                return(true);
            }
                private static bool SendCompletion(IAsyncResult result)
                {
                    DuplexRequestBindingElement.DuplexRequestSessionChannel.DuplexCorrelationAsyncResult duplexCorrelationAsyncResult;
                    bool      flag      = false;
                    bool      flag1     = true;
                    Exception exception = null;

                    DuplexRequestBindingElement.DuplexRequestSessionChannel.DuplexCorrelationAsyncResult asyncState = (DuplexRequestBindingElement.DuplexRequestSessionChannel.DuplexCorrelationAsyncResult)result.AsyncState;
                    try
                    {
                        try
                        {
                            asyncState.parent.innerChannel.EndSend(result);
                        }
                        catch (Exception exception2)
                        {
                            Exception exception1 = exception2;
                            if (Fx.IsFatal(exception1))
                            {
                                throw;
                            }
                            exception = exception1;
                            flag      = true;
                            if (ReconnectBindingElement.IsRetryable(asyncState.wcfRequest, exception))
                            {
                                flag1 = false;
                            }
                        }
                    }
                    finally
                    {
                        if (flag1 && asyncState.wcfRequest != null)
                        {
                            asyncState.wcfRequest.SafeClose();
                        }
                        asyncState.wcfRequest = null;
                    }
                    if (flag)
                    {
                        asyncState.parent.inflightRequests.TryRemove(asyncState.RequestMessageId, out duplexCorrelationAsyncResult);
                        asyncState.TryComplete(result.CompletedSynchronously, exception);
                    }
                    return(false);
                }
 private void CancelPendingOperations(bool isFaulted)
 {
     this.CancelPing();
     if (Interlocked.Exchange(ref this.interlockedSync, 1) == 0)
     {
         foreach (DuplexRequestBindingElement.DuplexRequestSessionChannel.DuplexCorrelationAsyncResult value in this.inflightRequests.Values)
         {
             DuplexRequestBindingElement.DuplexRequestSessionChannel.DuplexCorrelationAsyncResult duplexCorrelationAsyncResult = value;
             string    str = SRClient.TrackableExceptionMessageFormat(SRClient.ServerDidNotReply, duplexCorrelationAsyncResult.CreateClientTrackingExceptionInfo());
             Exception communicationObjectAbortedException = new CommunicationObjectAbortedException(str);
             if (isFaulted)
             {
                 communicationObjectAbortedException = new CommunicationObjectFaultedException(str);
             }
             ActionItem.Schedule((object s) => duplexCorrelationAsyncResult.TryComplete(false, communicationObjectAbortedException), null);
         }
         this.inflightRequests.Clear();
     }
 }