示例#1
0
        public void CloseInput(TimeSpan timeout)
        {
            SyncCommunicationWaiter waiter = null;

            lock (base.ThisLock)
            {
                if (this.activityCount > 0)
                {
                    waiter = new SyncCommunicationWaiter(base.ThisLock);
                    ICommunicationWaiter activityWaiter = this.activityWaiter;
                    this.activityWaiter = waiter;
                    Interlocked.Increment(ref this.activityWaiterCount);
                }
            }
            if (waiter != null)
            {
                CommunicationWaitResult result = waiter.Wait(timeout, false);
                if (Interlocked.Decrement(ref this.activityWaiterCount) == 0)
                {
                    waiter.Dispose();
                    this.activityWaiter = null;
                }
                switch (result)
                {
                case CommunicationWaitResult.Expired:
                    throw DiagnosticUtility.ExceptionUtility.ThrowHelperError(new TimeoutException(System.ServiceModel.SR.GetString("SfxCloseTimedOutWaitingForDispatchToComplete")));

                case CommunicationWaitResult.Aborted:
                    throw DiagnosticUtility.ExceptionUtility.ThrowHelperError(new ObjectDisposedException(base.GetType().ToString()));
                }
            }
        }
        public void CloseInput(TimeSpan timeout)
        {
            SyncCommunicationWaiter activityWaiter = null;

            lock (ThisLock)
            {
                if (ActivityCount > 0)
                {
                    activityWaiter = new SyncCommunicationWaiter(ThisLock);
                    if (!(_activityWaiter == null))
                    {
                        Fx.Assert("ServiceChannelManager.CloseInput: (this.activityWaiter == null)");
                    }
                    _activityWaiter = activityWaiter;
                    Interlocked.Increment(ref _activityWaiterCount);
                }
            }

            if (activityWaiter != null)
            {
                CommunicationWaitResult result = activityWaiter.Wait(timeout, false);
                if (Interlocked.Decrement(ref _activityWaiterCount) == 0)
                {
                    activityWaiter.Dispose();
                    _activityWaiter = null;
                }

                switch (result)
                {
                case CommunicationWaitResult.Expired:
                    throw DiagnosticUtility.ExceptionUtility.ThrowHelperError(new TimeoutException(SR.SfxCloseTimedOutWaitingForDispatchToComplete));

                case CommunicationWaitResult.Aborted:
                    throw DiagnosticUtility.ExceptionUtility.ThrowHelperError(new ObjectDisposedException(GetType().ToString()));
                }
            }
        }