Пример #1
0
 internal void WaitUntilComplete()
 {
     if (!IsCompleted)
     {
         AsyncWaitHandle.WaitOne();
     }
 }
Пример #2
0
        public Message WaitForReply(TimeSpan timeout)
        {
            var retval = AsyncWaitHandle.WaitOne((int)timeout.TotalMilliseconds, false);

            lock (ThisLock)
            {
                Dispose(false);

                if (_aborted)
                {
                    if (_requestException != null)
                    {
                        throw _requestException;
                    }
                    else
                    {
                        throw new CommunicationObjectAbortedException("RequestContext aborted");
                    }
                }
                if (retval == false)
                {
                    Abort();
                    throw new CommunicationObjectAbortedException("RequestContext timeout");
                }
            }
            return(_response);
        }
Пример #3
0
        /// <summary>
        /// Frees up resources used by the asynchronous operation represented by the IAsyncResult passed.
        /// If the asynchronous operation failed, this method throws the exception.
        /// </summary>
        public void EndInvoke()
        {
            // This method assumes that only 1 thread calls EndInvoke for this object

            // If the operation isn't done or if the wait handle was created, wait for it
            if (!IsCompleted || (m_AsyncWaitHandle != null))
            {
                AsyncWaitHandle.WaitOne();
            }

            // If the wait handle was created, close it
#pragma warning disable 420
            ManualResetEvent mre = Interlocked.Exchange(ref m_AsyncWaitHandle, null);
#pragma warning restore 420
            if (mre != null)
            {
                mre.Close();
            }

            // Operation is done: if an exception occurred, throw it
            if (m_exception != null)
            {
                throw m_exception;
            }
        }
Пример #4
0
 /// <devdoc>
 ///    <para>
 ///       Causes an abort of any aborted requests waiting in the ConnectionGroup
 ///    </para>
 /// </devdoc>
 private void Abort()
 {
     lock (m_ConnectionList) {
         m_Abort = true;
         AsyncWaitHandle.Set();
     }
 }
Пример #5
0
 /// <summary>
 /// Waits for completion.
 /// </summary>
 public void WaitForCompletion()
 {
     if (!isCompleted)
     {
         AsyncWaitHandle.WaitOne();
     }
 }
Пример #6
0
            internal bool End()
            {
                if (_ended)
                {
                    throw new InvalidOperationException();
                }

                _ended = true;

                if (!IsCompleted)
                {
                    AsyncWaitHandle.WaitOne();
                }

                if (_event != null)
                {
                    _event.Close();
                }

                if (_exception != null)
                {
                    throw _exception;
                }

                return(_aborted);
            }
Пример #7
0
 public void Dispose()
 {
     if (AsyncWaitHandle != null)
     {
         AsyncWaitHandle.Dispose();
         _handle = null;
     }
 }
Пример #8
0
 /// <devdoc>
 ///    <para>
 ///       Causes an abort of any aborted requests waiting in the ConnectionGroup
 ///    </para>
 /// </devdoc>
 private bool Abort(HttpWebRequest request, WebException webException)
 {
     lock (m_ConnectionList)
     {
         AsyncWaitHandle.Set();
     }
     return(true);
 }
Пример #9
0
 internal bool WaitUntilComplete(int timeout, bool exitContext)
 {
     if (IsCompleted)
     {
         return(true);
     }
     return(AsyncWaitHandle.WaitOne(timeout, exitContext));
 }
Пример #10
0
 internal void WaitUntilComplete()
 {
     if (_isCompleted)
     {
         return;
     }
     AsyncWaitHandle.WaitOne();
 }
Пример #11
0
 public WaitAsyncResult(AsyncWaitHandle waitHandle, AsyncCallback callback, object state, TimeSpan timeout) : base(callback, state)
 {
     this.waitHandle = waitHandle;
     if (this.waitHandle.WaitAsync(PrefetchAsyncWaitHandle.WaitAsyncResult.onWaitCallback, this, timeout))
     {
         base.Complete(true);
     }
 }
Пример #12
0
        public void Wait()
        {
            if (IsCompleted)
            {
                return;
            }

            AsyncWaitHandle.WaitOne();
        }
Пример #13
0
 /// <devdoc>
 ///    <para>
 ///       Called when a connection is idle and ready to process new requests
 ///    </para>
 /// </devdoc>
 internal void ConnectionGoneIdle()
 {
     if (m_AuthenticationGroup)
     {
         lock (m_ConnectionList) {
             AsyncWaitHandle.Set();
         }
     }
 }
Пример #14
0
 internal int Wait()
 {
     AsyncWaitHandle.WaitOne();
     if (Error != null)
     {
         throw Error;
     }
     return(ReadCount);
 }
 internal CloseAsyncResult(AsyncWaitHandle asyncWaitHandle, TimeSpan timeout, AsyncCallback callback, object state)
     : base(callback, state)
 {
     this.asyncWaitHandle = asyncWaitHandle;
     if (this.asyncWaitHandle.WaitAsync(onWaitCompleted, this, timeout))
     {
         Complete(true);
     }
 }
Пример #16
0
 /// <devdoc>
 ///    <para>
 ///       Called when a connection is idle and ready to process new requests
 ///    </para>
 /// </devdoc>
 internal void ConnectionGoneIdle()
 {
     if (m_AuthenticationGroup)
     {
         lock (m_ConnectionList) {
             GlobalLog.Print("ConnectionGroup::ConnectionGoneIdle() setting the event");
             AsyncWaitHandle.Set();
         }
     }
 }
Пример #17
0
 internal byte[] End(  )       // Wait for completion + rethrow any error.
 {
     AsyncWaitHandle.WaitOne(  );
     AsyncWaitHandle.Close(  );
     if (_exception != null)
     {
         throw _exception;
     }
     return(_data);
 }
Пример #18
0
 internal void ErrorCleanup()
 {
     if (pOverlapped != null)
     {
         Overlapped.Unpack(pOverlapped);
         Overlapped.Free(pOverlapped);
         pOverlapped = null;
     }
     AsyncWaitHandle.Close();
 }
Пример #19
0
 void Dispose(bool disposing)
 {
     if (disposing)
     {
         if (AsyncWaitHandle != null)
         {
             AsyncWaitHandle.Close();
         }
     }
 }
        internal void EndInvoke()
        {
            AsyncWaitHandle.WaitOne();
            AsyncWaitHandle.Close();
            _completedWaitHandle = null; // allow early GC

            if (null != _exception)
            {
                throw _exception;
            }
        }
Пример #21
0
        internal IMessage EndInvoke()
        {
            lock (this) {
                if (completed)
                {
                    return(reply_message);
                }
            }

            AsyncWaitHandle.WaitOne();
            return(reply_message);
        }
Пример #22
0
        /// <summary>
        /// When called in the dervied classes, wait for completion.
        /// It throws exception if the async operation ends with an exception.
        /// </summary>
        protected void WaitForCompletion()
        {
            if (!IsCompleted)
            {
                AsyncWaitHandle.WaitOne();
            }

            if (_exception != null)
            {
                throw _exception;
            }
        }
Пример #23
0
 internal WebResponse WaitForResponse()
 {
     if (!isCompleted)
     {
         AsyncWaitHandle.WaitOne();
     }
     if (exception != null)
     {
         throw exception;
     }
     return(response);
 }
Пример #24
0
 internal int Complete()
 {
     lock (MonitorWaitHandle) if (!IsCompleted)
         {
             Monitor.Wait(MonitorWaitHandle);
         }
     if (ErrorCode != 0)
     {
         throw new Win32Exception(ErrorCode);
     }
     AsyncWaitHandle.Close();
     return(Result);
 }
Пример #25
0
 public T FetchResultsFromAsyncOperation()
 {
     if (!_isCompleted)
     {
         AsyncWaitHandle.WaitOne();
         AsyncWaitHandle.Close();
     }
     if (_exception != null)
     {
         throw _exception;
     }
     return(_result);
 }
Пример #26
0
            public void EndConnect()
            {
                if (!fComplete)
                {
                    AsyncWaitHandle.WaitOne();
                }

                this.Dispose();
                if (this.fFailure != null)
                {
                    throw this.fFailure;
                }
            }
Пример #27
0
 public void EndInvoke()
 {
     if (!IsCompleted)
     {
         AsyncWaitHandle.WaitOne();
         AsyncWaitHandle.Close();
         m_AsyncWaitHandle = null;
     }
     if (m_exception != null)
     {
         throw m_exception;
     }
 }
Пример #28
0
        /// <summary>
        /// Task EndXXX method called
        /// </summary>
        public void EndInvoke()
        {
            if (!IsCompleted)
            {
                AsyncWaitHandle.WaitOne();
                AsyncWaitHandle.Close();
                _waitHandle = null;
            }

            if (_terminatingException != null)
            {
                throw _terminatingException;
            }
        }
Пример #29
0
        // we're guaranteed by CommunicationObject that at most ONE of Close or BeginClose will be called once.
        private void Cleanup(bool aborting, TimeSpan timeout)
        {
            bool needToWait = false;

            if (this.cleanedUp)
            {
                return;
            }

            lock (this.ThisLock)
            {
                if (this.cleanedUp)
                {
                    return;
                }

                if (!aborting && this.retransmitList != null && this.retransmitList.Count > 0)
                {
                    needToWait = true;
                    this.retransmissionDoneWaitHandle = new AsyncWaitHandle(EventResetMode.ManualReset);
                }
                else
                {
                    // copied this call here in order to avoid releasing then retaking lock
                    this.CleanupAfterWait(aborting);
                }
            }

            if (needToWait)
            {
                if (!this.retransmissionDoneWaitHandle.Wait(timeout))
                {
                    throw FxTrace.Exception.AsError(new TimeoutException(SR.TimeoutOnOperation(timeout)));
                }

                lock (this.ThisLock)
                {
                    this.retransmissionDoneWaitHandle = null;

                    // another thread could have called Abort while Close() was waiting for retransmission to complete.
                    if (this.cleanedUp)
                    {
                        return;
                    }

                    this.CleanupAfterWait(aborting);
                }
            }
        }
Пример #30
0
 internal T EndOperation()
 {
     while (true)
     {
         if (IsCompleted)
         {
             if (Exception != null)
             {
                 throw Exception;
             }
             return(Result);
         }
         AsyncWaitHandle.WaitOne();
     }
 }
            public void SetInteriorTransaction(Transaction interiorTransaction, bool needsCommit)
            {
                Fx.Assert(!this.context.IsHostTransaction, "SetInteriorTransaction called for a host transaction.");

                if (this.waitForTransaction != null)
                {
                    throw Fx.Exception.AsError(new InvalidOperationException(SRCore.ExecuteMustBeNested));
                }

                bool success = false;
                try
                {
                    this.waitForTransaction = new AsyncWaitHandle(EventResetMode.ManualReset);
                    interiorTransaction.EnlistVolatile(this, EnlistmentOptions.None);
                    success = true;
                }
                finally
                {
                    if (!success)
                    {
                        if (this.waitForTransaction != null)
                        {
                            this.waitForTransaction.Set();
                        }
                    }
                    else if (needsCommit)
                    {
                        this.transactionToCommit = (CommittableTransaction)interiorTransaction;
                    }
                }
            }
            public BindReclaimedLockAsyncResult(InstancePersistenceContext context, AsyncWaitHandle wait, TimeSpan timeout, AsyncCallback callback, object state)
                : base(callback, state)
            {
                this.context = context;

                if (wait.WaitAsync(BindReclaimedLockAsyncResult.waitComplete, this, timeout))
                {
                    this.context.ConcludeBindReclaimedLockHelper();
                    Complete(true);
                }
            }
 internal BindReclaimedLockException(AsyncWaitHandle markerWaitHandle)
     : base(SRCore.BindReclaimedLockException)
 {
     MarkerWaitHandle = markerWaitHandle;
 }
Пример #34
0
            bool DoAfterTransaction()
            {
                AcquireContextAsyncResult setWaitTo = null;
                try
                {
                    lock (this.handle.ThisLock)
                    {
                        if (!this.handle.IsValid)
                        {
                            throw Fx.Exception.AsError(new OperationCanceledException(SRCore.HandleFreed));
                        }

                        if (HostTransaction == null)
                        {
                            this.executionContext = new InstancePersistenceContext(this.handle, this.timeoutHelper.RemainingTime());
                        }
                        else
                        {
                            this.executionContext = new InstancePersistenceContext(this.handle, HostTransaction);
                        }

                        this.handle.AcquirePending = null;
                        this.handle.CurrentExecutionContext = this.executionContext;
                        this.handle.TooLateToEnlist = false;
                    }

                    if (HostTransaction != null)
                    {
                        WaitForHostTransaction = new AsyncWaitHandle(EventResetMode.ManualReset);
                        HostTransaction.EnlistVolatile(this, EnlistmentOptions.None);
                        setWaitTo = this;
                    }
                }
                finally
                {
                    this.handle.CurrentTransactionalAsyncResult = setWaitTo;
                }

                return true;
            }