public void WaitOnHandle(WaitHandle waitHandle, TimeSpan operationTimeout)
{
var waitHandles = new[]
{
_errorOccuredWaitHandle,
_sessionDisconnectedWaitHandle,
_channelClosedWaitHandle,
waitHandle
};
switch (WaitHandle.WaitAny(waitHandles, operationTimeout))
{
case 0:
throw _exception;
case 1:
throw new SshException("Connection was closed by the server.");
case 2:
throw new SshException("Channel was closed.");
case WaitHandle.WaitTimeout:
throw new SshOperationTimeoutException(string.Format(CultureInfo.CurrentCulture, "Operation has timed out."));
}
}