/// <summary> /// Begins an asynchronous operation of retrieving list of files in remote directory. /// </summary> /// <param name="path">The path.</param> /// <param name="asyncCallback">The method to be called when the asynchronous write operation is completed.</param> /// <param name="state">A user-provided object that distinguishes this particular asynchronous write request from other requests.</param> /// <param name="listCallback">The list callback.</param> /// <returns> /// An <see cref="IAsyncResult" /> that references the asynchronous operation. /// </returns> /// <exception cref="ObjectDisposedException">The method was called after the client was disposed.</exception> public IAsyncResult BeginListDirectory(string path, AsyncCallback asyncCallback, object state, Action<int> listCallback = null) { CheckDisposed(); var asyncResult = new SftpListDirectoryAsyncResult(asyncCallback, state); ExecuteThread(() => { try { var result = InternalListDirectory(path, count => { asyncResult.Update(count); if (listCallback != null) { listCallback(count); } }); asyncResult.SetAsCompleted(result, false); } catch (Exception exp) { asyncResult.SetAsCompleted(exp, false); } }); return asyncResult; }
/// <summary> /// Begins an asynchronous operation of retrieving list of files in remote directory. /// </summary> /// <param name="path">The path.</param> /// <param name="asyncCallback">The method to be called when the asynchronous write operation is completed.</param> /// <param name="state">A user-provided object that distinguishes this particular asynchronous write request from other requests.</param> /// <returns> /// An <see cref="IAsyncResult"/> that references the asynchronous operation. /// </returns> public IAsyncResult BeginListDirectory(string path, AsyncCallback asyncCallback, object state) { var asyncResult = new SftpListDirectoryAsyncResult(asyncCallback, state); this.ExecuteThread(() => { try { var result = this.InternalListDirectory(path, asyncResult); asyncResult.SetAsCompleted(result, false); } catch (Exception exp) { asyncResult.SetAsCompleted(exp, false); } }); return asyncResult; }