Ejemplo n.º 1
0
 internal void ErrorCleanup()
 {
     if (pOverlapped != null)
     {
         Overlapped.Unpack(pOverlapped);
         Overlapped.Free(pOverlapped);
         pOverlapped = null;
     }
     AsyncWaitHandle.Close();
 }
Ejemplo n.º 2
0
 internal byte[] End(  )       // Wait for completion + rethrow any error.
 {
     AsyncWaitHandle.WaitOne(  );
     AsyncWaitHandle.Close(  );
     if (_exception != null)
     {
         throw _exception;
     }
     return(_data);
 }
Ejemplo n.º 3
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;
            }
        }
Ejemplo n.º 5
0
 public T FetchResultsFromAsyncOperation()
 {
     if (!_isCompleted)
     {
         AsyncWaitHandle.WaitOne();
         AsyncWaitHandle.Close();
     }
     if (_exception != null)
     {
         throw _exception;
     }
     return(_result);
 }
Ejemplo n.º 6
0
 internal int Complete()
 {
     lock (MonitorWaitHandle) if (!IsCompleted)
         {
             Monitor.Wait(MonitorWaitHandle);
         }
     if (ErrorCode != 0)
     {
         throw new Win32Exception(ErrorCode);
     }
     AsyncWaitHandle.Close();
     return(Result);
 }
Ejemplo n.º 7
0
 public void EndInvoke()
 {
     if (!IsCompleted)
     {
         AsyncWaitHandle.WaitOne();
         AsyncWaitHandle.Close();
         m_AsyncWaitHandle = null;
     }
     if (m_exception != null)
     {
         throw m_exception;
     }
 }
Ejemplo n.º 8
0
        /// <summary>
        /// Task EndXXX method called
        /// </summary>
        public void EndInvoke()
        {
            if (!IsCompleted)
            {
                AsyncWaitHandle.WaitOne();
                AsyncWaitHandle.Close();
                _waitHandle = null;
            }

            if (_terminatingException != null)
            {
                throw _terminatingException;
            }
        }
Ejemplo n.º 9
0
 /// <summary>
 /// 等待同步完成,它将阻塞当前线程,直至等待超过timeout时限,或等待事件被设置。
 /// </summary>
 /// <param name="timeout">等待的毫秒数。-1表示无限期等待。</param>
 public void EndInvoke(int timeout)
 {
     // This method assumes that only 1 thread calls EndInvoke for this object
     if (!IsCompleted)
     {
         // If the operation isn't done, wait for it
         //Translated from Java, -1 means wait to done
         if (-1 == timeout)
         {
             timeout = 0;
         }
         AsyncWaitHandle.WaitOne(timeout, false);
         AsyncWaitHandle.Close();
         asyncWaitHandle = null;
     }
 }
Ejemplo n.º 10
0
        public void EndInvoke()
        {
            // This method assumes that only 1 thread calls EndInvoke for this object
            if (!IsCompleted)
            {
                // If the operation isn't done, wait for it
                AsyncWaitHandle.WaitOne();
                AsyncWaitHandle.Close();
                m_AsyncWaitHandle = null;  // Allow early GC
            }

            // Operation is done: if an exception occured, throw it
            if (m_exception != null)
            {
                throw m_exception;
            }
        }
Ejemplo n.º 11
0
        /// <summary>
        /// Waits until the asynchronous operation completes, and then returns.
        /// </summary>
        public void EndInvoke()
        {
            // This method assumes that only 1 thread calls EndInvoke for this object
            if (!this.IsCompleted)
            {
                // If the operation isn't done, wait for it
                AsyncWaitHandle.WaitOne();
                AsyncWaitHandle.Close();
                this._asyncWaitHandle = null;  // Allow early GC
            }

            this.EndInvokeCalled = true;

            // Operation is done: if an exception occurred, throw it
            if (this._exception != null)
            {
                throw new SshException(this._exception.Message, this._exception);
            }
        }
Ejemplo n.º 12
0
            internal void Get()
            {
                if (IsCompleted == false)
                {
                    try
                    {
                        AsyncWaitHandle.WaitOne();
                    }
                    finally
                    {
                        AsyncWaitHandle.Close();
                    }
                }

                if (exception != null)
                {
                    throw exception;
                }
            }
Ejemplo n.º 13
0
        internal void EndInvoke(bool canThrowException)
        {
            // This method assumes that only 1 thread calls EndInvoke
            // for this object
            if (!IsCompleted)
            {
                // If the operation isn't done, wait for it
                AsyncWaitHandle.WaitOne();
                AsyncWaitHandle.Close();
                _asyncWaitHandle = null;                  // Allow early GC
            }

            // Operation is done: if an error occured, throw it
            if (canThrowException)
            {
                if (SocketError != RUDPSocketError.Success)
                {
                    throw new RUDPSocketException(SocketError);
                }
            }
        }
Ejemplo n.º 14
0
            public void EndInvoke()
            {
                // This method assumes that only 1 thread calls EndInvoke
                // for this object
                if (!IsCompleted)
                {
                    // If the operation isn't done, wait for it
                    AsyncWaitHandle.WaitOne();
#if (NETCOREAPP1_0 || NETCOREAPP2_0)
                    AsyncWaitHandle.Dispose();
#else
                    AsyncWaitHandle.Close();
#endif
                    this.asyncWaitHandle = null;
                    // Allow early GC
                }

                // Operation is done: if an exception occured, throw it
                if (this.exception != null)
                {
                    throw this.exception;
                }
            }
Ejemplo n.º 15
0
        public void EndInvoke()
        {
            // This method assumes that only 1 thread calls EndInvoke
            // for this object
            if (!IsCompleted)
            {
                // If the operation isn't done, wait for it
                AsyncWaitHandle.WaitOne();
                AsyncWaitHandle.Close();
                m_AsyncWaitHandle = null; // Allow early GC
            }

            // Operation is done: if an exception occured, throw it
            if (m_exception != null)
            {
                throw new Exception(String.Format(
                                        "{0} was thrown in thread #{1} carrying state ({2}).",
                                        m_exception.GetType().FullName,
                                        Thread.CurrentThread.ManagedThreadId,
                                        m_AsyncState),
                                    m_exception);
            }
        }
Ejemplo n.º 16
0
        public void EndInvoke()
        {
            Log("EndInvoke (enter)");

            // This method assumes that only 1 thread calls EndInvoke
            // for this object
            if (!IsCompleted)
            {
                Log("Waiting on handle...");
                // If the operation isn't done, wait for it
                AsyncWaitHandle.WaitOne();
                AsyncWaitHandle.Close();
                _resetEvent = null; // Allow early GC
            }

            // Operation is done: if an exception occured, throw it
            if (_exception != null)
            {
                Log("Exception encountered: {0}", _exception.Message);
                throw _exception;
            }
            Log("EndInvoke (exit)");
        }