Skip to content

Commit f8d4e13

Browse files
committed
improve comments
1 parent b3b4b42 commit f8d4e13

File tree

1 file changed

+12
-15
lines changed

1 file changed

+12
-15
lines changed

snippets/csharp/System.Net/HttpWebRequest/Abort/begingetresponse.cs

Lines changed: 12 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,9 @@
11
/**
22
* File name: Begingetresponse.cs
33
* This program shows how to use BeginGetResponse and EndGetResponse methods of the
4-
* HttpWebRequest class. It also shows how to create a customized timeout.
5-
* This is important in case od asynchronous request, because the NCL classes do
6-
* not provide any off-the-shelf asynchronous timeout.
7-
* It uses an asynchronous approach to get the response for the HTTP Web Request.
8-
* The RequestState class is defined to chekc the state of the request.
4+
* HttpWebRequest class.
5+
* It uses the APM pattern to get the response for the HTTP Web Request.
6+
* The RequestState class is defined to check the state of the request.
97
* After a HttpWebRequest object is created, its BeginGetResponse method is used to start
108
* the asynchronous response phase.
119
* Finally, the EndGetResponse method is used to end the asynchronous response phase .*/
@@ -43,22 +41,21 @@ public static void Main()
4341
{
4442
try
4543
{
46-
// Create a HttpWebrequest object to the desired URL.
47-
WebRequest httpWebRequest = WebRequest.Create("http://www.contoso.com");
48-
httpWebRequest.Timeout = 10_000; // Set 10sec timeout.
44+
// Create a WebRequest object to the desired URL.
45+
WebRequest webRequest = WebRequest.Create("http://www.contoso.com");
46+
webRequest.Timeout = 10_000; // Set 10sec timeout.
4947

5048
// Create an instance of the RequestState and assign the previous myHttpWebRequest
5149
// object to its request field.
52-
RequestState requestState = new RequestState(httpWebRequest);
50+
RequestState requestState = new RequestState(webRequest);
5351

5452
// Start the asynchronous request.
55-
IAsyncResult result = httpWebRequest.BeginGetResponse(new AsyncCallback(ResponseCallback), requestState);
53+
IAsyncResult result = webRequest.BeginGetResponse(new AsyncCallback(ResponseCallback), requestState);
5654

57-
// The response came in the allowed time. The work processing will happen in the
58-
// callback function.
55+
// Wait for the response or for failure. The processing happens in the callback.
5956
allDone.WaitOne();
6057

61-
// Release the HttpWebResponse resource.
58+
// Release the WebResponse resources.
6259
requestState.Response?.Close();
6360
}
6461
catch (WebException e)
@@ -105,12 +102,12 @@ private static void ResponseCallback(IAsyncResult asynchronousResult)
105102
{
106103
try
107104
{
108-
// State of request is asynchronous.
105+
// AsyncState is an instance of RequestState.
109106
RequestState requestState = (RequestState)asynchronousResult.AsyncState;
110107
WebRequest request = requestState.Request;
111108
requestState.Response = request.EndGetResponse(asynchronousResult);
112109

113-
// Read the response into a Stream object.
110+
// Read the response into a Stream.
114111
Stream responseStream = requestState.Response.GetResponseStream();
115112
requestState.ResponseStream = responseStream;
116113

0 commit comments

Comments
 (0)