SftpAsyncResult.cs 1.6 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758
  1. using System;
  2. using System.Collections.Generic;
  3. using System.Threading;
  4. using Renci.SshClient.Common;
  5. namespace Renci.SshClient
  6. {
  7. public class SftpAsyncResult : IAsyncResult
  8. {
  9. private bool _isCompleted;
  10. private Channels.ChannelSession _channelSession;
  11. private AsyncCallback _callback;
  12. private EventWaitHandle _completedWaitHandle = new ManualResetEvent(false);
  13. public IList<FtpFileInfo> Names { get; internal set; }
  14. internal SftpAsyncResult(Channels.ChannelSession channelSession, AsyncCallback callback, object state)
  15. {
  16. this._channelSession = channelSession;
  17. this._callback = callback;
  18. this.AsyncState = state;
  19. this.AsyncWaitHandle = _completedWaitHandle;
  20. }
  21. #region IAsyncResult Members
  22. public object AsyncState { get; private set; }
  23. public WaitHandle AsyncWaitHandle { get; private set; }
  24. public bool CompletedSynchronously { get; private set; }
  25. public bool IsCompleted
  26. {
  27. get
  28. {
  29. return this._isCompleted;
  30. }
  31. internal set
  32. {
  33. this._isCompleted = value;
  34. if (value)
  35. {
  36. if (this._callback != null)
  37. {
  38. this._callback(this);
  39. }
  40. this._completedWaitHandle.Set();
  41. }
  42. }
  43. }
  44. #endregion
  45. }
  46. }