Renci.SshNet.SshCommand.EndExecute C# (CSharp) Method

EndExecute() public method

Waits for the pending asynchronous command execution to complete.
Either the IAsyncResult object did not come from the corresponding async method on this type, or EndExecute was called multiple times with the same IAsyncResult. is null.
public EndExecute ( IAsyncResult asyncResult ) : string
asyncResult IAsyncResult The reference to the pending asynchronous request to finish.
return string
        public string EndExecute(IAsyncResult asyncResult)
        {
            if (asyncResult == null)
            {
                throw new ArgumentNullException("asyncResult");
            }

            var commandAsyncResult = asyncResult as CommandAsyncResult;
            if (commandAsyncResult == null || _asyncResult != commandAsyncResult)
            {
                throw new ArgumentException(string.Format("The {0} object was not returned from the corresponding asynchronous method on this class.", typeof(IAsyncResult).Name));
            }

            lock (_endExecuteLock)
            {
                if (commandAsyncResult.EndCalled)
                {
                    throw new ArgumentException("EndExecute can only be called once for each asynchronous operation.");
                }

                //  wait for operation to complete (or time out)
                WaitOnHandle(_asyncResult.AsyncWaitHandle);

                UnsubscribeFromEventsAndDisposeChannel(_channel);
                _channel = null;

                commandAsyncResult.EndCalled = true;

                return Result;
            }
        }

Usage Example

コード例 #1
0
ファイル: SshCommand.cs プロジェクト: waffle-iron/nequeo
 /// <summary>
 /// Waits for the pending asynchronous command execution to complete.
 /// </summary>
 /// <param name="asyncResult">The reference to the pending asynchronous request to finish.</param>
 /// <returns>Command execution result.</returns>
 public string EndExecute(IAsyncResult asyncResult)
 {
     return(_sshCommand.EndExecute(asyncResult));
 }