diff --git a/src/Renci.SshNet/Common/AsyncResult.cs b/src/Renci.SshNet/Common/AsyncResult.cs index 70726ed4..066f4015 100644 --- a/src/Renci.SshNet/Common/AsyncResult.cs +++ b/src/Renci.SshNet/Common/AsyncResult.cs @@ -29,10 +29,12 @@ namespace Renci.SshNet.Common private Exception _exception; /// - /// Gets or sets a value indicating whether EndInvoke has been called on the current AsyncResult. + /// Gets or sets a value indicating whether has been called on the current + /// . /// /// - /// true if has been called on the current ; otherwise, false. + /// true if has been called on the current ; + /// otherwise, false. /// public bool EndInvokeCalled { get; private set; } @@ -75,15 +77,24 @@ namespace Renci.SshNet.Common /// /// Waits until the asynchronous operation completes, and then returns. /// - public void EndInvoke() + internal void EndInvoke() + { + EndInvoke(Session.InfiniteTimeSpan); + } + + /// + /// Waits until the asynchronous operation completes, and then returns. + /// + internal void EndInvoke(TimeSpan timeout) { // 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(); + var completed = AsyncWaitHandle.WaitOne(timeout); _asyncWaitHandle = null; // Allow early GC + AsyncWaitHandle.Dispose(); + } EndInvokeCalled = true;