public CloseOutputSessionAsyncResult(LocalDuplexSessionChannel channel, TimeSpan timeout, AsyncCallback callback, object state)
                : base(callback, state)
            {
                if (channel.State == CommunicationState.Created ||
                    channel.State == CommunicationState.Opening ||
                    channel.State == CommunicationState.Faulted)
                {
                    throw new InvalidOperationException(ExceptionMessages.CommunicationObjectInInvalidState);
                }

                this.channel = channel;

                bool shutDownSuccess = false;

                try
                {
                    this.channel.OnOutputSessionClosed();
                    shutDownSuccess = true;
                }
                finally
                {
                    if (!shutDownSuccess)
                    {
                        this.channel.Fault();
                    }
                }

                base.Complete(true);
            }
 public SendAsyncResult(LocalDuplexSessionChannel channel, Message message, TimeSpan timeout, AsyncCallback callback, object state)
     : base(callback, state)
 {
     this.channel = channel;
     this.message = channel.PrepareMessageForSend(message);
     this.channel.sendQueue.EnqueueAndDispatch(this.message, this.channel.onItemDequeued, false);
     this.Complete(true);
 }
            public HelpReceiveAsyncResult(LocalDuplexSessionChannel channel, TimeSpan timeout,
                                          AsyncCallback callback, object state)
                : base(callback, state)
            {
                this.channel = channel;
                this.timeout = timeout;
                IAsyncResult result = channel.BeginTryReceive(timeout, onReceive, this);

                if (!result.CompletedSynchronously)
                {
                    return;
                }

                HandleReceiveComplete(result);
                base.Complete(true);
            }
            public CloseAsyncResult(LocalDuplexSessionChannel channel, TimeSpan timeout, AsyncCallback callback, object state)
                : base(callback, state)
            {
                if (channel.State == CommunicationState.Created ||
                    channel.State == CommunicationState.Opening ||
                    channel.State == CommunicationState.Faulted)
                {
                    throw new InvalidOperationException(ExceptionMessages.CommunicationObjectInInvalidState);
                }
                this.timeouthelper = new TimeoutHelper(timeout);
                this.channel       = channel;
                bool         completeSelf = false;
                IAsyncResult result       = this.channel.BeginCloseOutputSession(timeout,
                                                                                 PrepareAsyncCompletion(CloseOutputSessionCallback), this);

                if (result.CompletedSynchronously)
                {
                    completeSelf = OnOutputSessionClosed(result);
                }
                if (completeSelf)
                {
                    base.Complete(true);
                }
            }
 public LocalDuplexSession(LocalDuplexSessionChannel channel)
     : base()
 {
     this.channel = channel;
     this.id      = Guid.NewGuid().ToString();
 }