Beispiel #1
0
 public void Dispose()
 {
     if (AsyncWaitHandle != null)
     {
         AsyncWaitHandle.Dispose();
         _handle = null;
     }
 }
Beispiel #2
0
 public void EndInvoke()
 {
     lock (_lock)
     {
         if (!IsCompleted)
         {
             AsyncWaitHandle.WaitOne();
             AsyncWaitHandle.Dispose(); _asyncWaitHandle = null;
         }
     }
     if (_exception != null)
     {
         throw _exception;
     }
 }
Beispiel #3
0
        /// <summary>
        /// Wait for the operation to complete and throw the exception if any.
        /// </summary>
        internal void EndInvoke()
        {
            _invokeOnThreadEvent = new AutoResetEvent(false);

            // Start the thread wait loop.
            WaitHandle[] waitHandles = new WaitHandle[2] {
                AsyncWaitHandle, _invokeOnThreadEvent
            };
            bool waiting = true;

            while (waiting)
            {
                int waitIndex = WaitHandle.WaitAny(waitHandles);

                if (waitIndex == 0)
                {
                    waiting = false;
                }
                else
                {
                    // Invoke callback on thread.
                    try
                    {
                        _invokeCallback(_invokeCallbackState);
                    }
                    catch (Exception e)
                    {
                        CommandProcessorBase.CheckForSevereException(e);
                    }
                }
            }

            AsyncWaitHandle.Dispose();
            _completedWaitHandle = null;  // Allow early GC

            _invokeOnThreadEvent.Dispose();
            _invokeOnThreadEvent = null;  // Allow early GC

            // Operation is done: if an exception occured, throw it
            if (null != Exception)
            {
                throw Exception;
            }
        }
Beispiel #4
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 (!IsCompleted)
            {
                // If the operation isn't done, wait for it
                AsyncWaitHandle.WaitOne();
                AsyncWaitHandle.Dispose();
                _asyncWaitHandle = null;  // Allow early GC
            }

            EndInvokeCalled = true;

            // Operation is done: if an exception occurred, throw it
            if (_exception != null)
            {
                throw new SshException(_exception.Message, _exception);
            }
        }
Beispiel #5
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;
                }
            }
Beispiel #6
0
 public void Dispose()
 {
     AsyncWaitHandle.Dispose();
 }