public void Dispose() { if (AsyncWaitHandle != null) { AsyncWaitHandle.Dispose(); _handle = null; } }
public void EndInvoke() { lock (_lock) { if (!IsCompleted) { AsyncWaitHandle.WaitOne(); AsyncWaitHandle.Dispose(); _asyncWaitHandle = null; } } if (_exception != null) { throw _exception; } }
/// <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; } }
/// <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); } }
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; } }
public void Dispose() { AsyncWaitHandle.Dispose(); }