2 // System.Web.Services.Protocols.WebClientAsyncResult.cs
\r
5 // Tim Coleman (tim@timcoleman.com)
\r
6 // Lluis Sanchez Gual (lluis@ximian.com)
\r
8 // Copyright (C) Tim Coleman, 2002
\r
12 // Permission is hereby granted, free of charge, to any person obtaining
13 // a copy of this software and associated documentation files (the
14 // "Software"), to deal in the Software without restriction, including
15 // without limitation the rights to use, copy, modify, merge, publish,
16 // distribute, sublicense, and/or sell copies of the Software, and to
17 // permit persons to whom the Software is furnished to do so, subject to
18 // the following conditions:
20 // The above copyright notice and this permission notice shall be
21 // included in all copies or substantial portions of the Software.
23 // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
24 // EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
25 // MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
26 // NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
27 // LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
28 // OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
29 // WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
33 using System.Threading;
\r
35 namespace System.Web.Services.Protocols {
\r
36 public class WebClientAsyncResult : IAsyncResult {
\r
40 AsyncCallback _callback;
\r
43 bool _completedSynchronously;
\r
45 ManualResetEvent _waitHandle;
\r
47 internal object Result;
\r
48 internal Exception Exception;
\r
49 internal WebRequest Request;
\r
51 #endregion // Fields
\r
53 #region Constructors
\r
55 internal WebClientAsyncResult (WebRequest request, AsyncCallback callback, object asyncState)
\r
57 _callback = callback;
\r
59 _asyncState = asyncState;
\r
62 #endregion // Constructors
\r
66 public object AsyncState {
\r
67 get { return _asyncState; }
\r
70 public WaitHandle AsyncWaitHandle
\r
75 if (_waitHandle != null) return _waitHandle;
\r
76 _waitHandle = new ManualResetEvent (_done);
\r
82 public bool CompletedSynchronously
\r
84 get { return _completedSynchronously; }
\r
87 public bool IsCompleted
\r
89 get { lock (this) { return _done; } }
\r
92 #endregion // Properties
\r
96 public void Abort ()
\r
101 internal void SetCompleted (object result, Exception exception, bool async)
\r
105 Exception = exception;
\r
108 _completedSynchronously = async;
\r
109 if (_waitHandle != null) _waitHandle.Set ();
\r
110 Monitor.PulseAll (this);
\r
112 if (_callback != null) _callback (this);
\r
115 internal void WaitForComplete ()
\r
119 Monitor.Wait (this);
\r
123 #endregion // Methods
\r