* HtmlFormParameterReader.cs, HtmlFormParameterWriter.cs,
[mono.git] / mcs / class / System.Web.Services / System.Web.Services.Protocols / WebClientAsyncResult.cs
1 // \r
2 // System.Web.Services.Protocols.WebClientAsyncResult.cs\r
3 //\r
4 // Author:\r
5 //   Tim Coleman (tim@timcoleman.com)\r
6 //   Lluis Sanchez Gual (lluis@ximian.com)\r
7 //\r
8 // Copyright (C) Tim Coleman, 2002\r
9 //\r
10 \r
11 using System.Net;\r
12 using System.Threading;\r
13 \r
14 namespace System.Web.Services.Protocols {\r
15         public class WebClientAsyncResult : IAsyncResult {\r
16 \r
17                 #region Fields\r
18 \r
19                 AsyncCallback _callback;\r
20                 object _asyncState;\r
21 \r
22                 bool _completedSynchronously;\r
23                 bool _done;\r
24                 ManualResetEvent _waitHandle;\r
25                 \r
26                 internal SoapClientMessage Message;\r
27                 internal SoapExtension[] Extensions;\r
28 \r
29                 internal object Result;\r
30                 internal Exception Exception;\r
31                 internal WebRequest Request;\r
32                         \r
33                 #endregion // Fields\r
34 \r
35                 #region Constructors \r
36 \r
37                 internal WebClientAsyncResult (WebRequest request, AsyncCallback callback, object asyncState)\r
38                 {\r
39                         _callback = callback; \r
40                         Request = request;\r
41                         _asyncState = asyncState;\r
42                 }\r
43 \r
44                 #endregion // Constructors\r
45 \r
46                 #region Properties\r
47 \r
48                 public object AsyncState {\r
49                         get { return _asyncState; }\r
50                 }\r
51 \r
52                 public WaitHandle AsyncWaitHandle \r
53                 {\r
54                         get\r
55                         {\r
56                                 lock (this) {\r
57                                         if (_waitHandle != null) return _waitHandle;\r
58                                         _waitHandle = new ManualResetEvent (_done);\r
59                                         return _waitHandle;\r
60                                 }\r
61                         }\r
62                 }\r
63 \r
64                 public bool CompletedSynchronously \r
65                 {\r
66                         get { return _completedSynchronously; }\r
67                 }\r
68 \r
69                 public bool IsCompleted \r
70                 {\r
71                         get { lock (this) { return _done; } }\r
72                 }\r
73 \r
74                 #endregion // Properties\r
75 \r
76                 #region Methods\r
77 \r
78                 public void Abort ()\r
79                 {\r
80                         Request.Abort ();\r
81                 }\r
82 \r
83                 internal void SetCompleted (object result, Exception exception, bool async)\r
84                 {\r
85                         lock (this)\r
86                         {\r
87                                 Exception = exception;\r
88                                 Result = result;\r
89                                 _done = true;\r
90                                 _completedSynchronously = async;\r
91                                 if (_waitHandle != null) _waitHandle.Set ();\r
92                                 Monitor.PulseAll (this);\r
93                         }\r
94                         if (_callback != null) _callback (this);\r
95                 }\r
96 \r
97                 internal void WaitForComplete ()\r
98                 {\r
99                         lock (this)\r
100                         {\r
101                                 Monitor.Wait (this);\r
102                         }\r
103                 }\r
104 \r
105                 #endregion // Methods\r
106         }\r
107 }