2 // System.Net.FtpAsyncResult.cs
5 // Carlos Alberto Cortez (calberto.cortez@gmail.com)
7 // (c) Copyright 2006 Novell, Inc. (http://www.novell.com)
12 using System.Threading;
18 class FtpAsyncResult : IAsyncResult
20 FtpWebResponse response;
21 ManualResetEvent waitHandle;
23 AsyncCallback callback;
28 object locker = new object ();
30 public FtpAsyncResult (AsyncCallback callback, object state)
32 this.callback = callback;
36 public object AsyncState {
42 public WaitHandle AsyncWaitHandle {
45 if (waitHandle == null)
46 waitHandle = new ManualResetEvent (false);
53 public bool CompletedSynchronously {
59 public bool IsCompleted {
67 internal bool GotException {
69 return exception != null;
73 internal Exception Exception {
79 internal FtpWebResponse Response {
88 internal Stream Stream {
94 internal void WaitUntilComplete ()
99 AsyncWaitHandle.WaitOne ();
102 internal bool WaitUntilComplete (int timeout, bool exitContext)
107 return AsyncWaitHandle.WaitOne (timeout, exitContext);
110 internal void SetCompleted (bool synch, Exception exc, FtpWebResponse response)
113 this.exception = exc;
114 this.response = response;
117 if (waitHandle != null)
122 internal void SetCompleted (bool synch)
124 SetCompleted (synch, null, null);
127 internal void SetCompleted (bool synch, FtpWebResponse response)
129 SetCompleted (synch, null, response);
132 internal void SetCompleted (bool synch, Exception exc)
134 SetCompleted (synch, exc, null);
137 internal void SetCompleted (bool synch, Stream stream)
140 this.stream = stream;
143 if (waitHandle != null)
148 internal void DoCallback ()
154 internal void Reset ()
163 if (waitHandle != null)