Added EndInvoke(TimeSpan timeout).

This commit is contained in:
Gert Driesen
2017-01-22 19:49:40 +01:00
parent 31e204b634
commit e643378cfc
+16 -5
View File
@@ -29,10 +29,12 @@ namespace Renci.SshNet.Common
private Exception _exception;
/// <summary>
/// Gets or sets a value indicating whether EndInvoke has been called on the current AsyncResult.
/// Gets or sets a value indicating whether <see cref="EndInvoke()"/> has been called on the current
/// <see cref="AsyncResult"/>.
/// </summary>
/// <value>
/// <c>true</c> if <see cref="EndInvoke()"/> has been called on the current <see cref="AsyncResult"/>; otherwise, <c>false</c>.
/// <c>true</c> if <see cref="EndInvoke()"/> has been called on the current <see cref="AsyncResult"/>;
/// otherwise, <c>false</c>.
/// </value>
public bool EndInvokeCalled { get; private set; }
@@ -75,15 +77,24 @@ namespace Renci.SshNet.Common
/// <summary>
/// Waits until the asynchronous operation completes, and then returns.
/// </summary>
public void EndInvoke()
internal void EndInvoke()
{
EndInvoke(Session.InfiniteTimeSpan);
}
/// <summary>
/// Waits until the asynchronous operation completes, and then returns.
/// </summary>
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;