Game Development Reference
In-Depth Information
Launch an asynchronous request to access a web resource.
IAsyncResult result =
request.BeginGetResponse(new AsyncCallback(ResponseCallback),
state) as IAsyncResult;
Wait for the complete event to be set so that the data is not returned until the call-
back finishes.
if (state.FixedSizeBuffer)
return state.StaticBuffer;
return state.DynamicBuffer.ToArray();
The following callback is used when an asynchronous response occurs.
private void ResponseCallback(IAsyncResult asyncResult)
Pull the asynchronous state object out of the result object, and then retrieve the request.
AsyncFileDownloadState state =
WebRequest request = state.Request;
Complete the asynchronous response and get the response object.
WebResponse response = request.EndGetResponse(asyncResult);
As an optimization, we check to see whether the data length of the requested
resource is known, so that an appropriate storage buffer can be used. With a
known length, a static buffer can be used, whereas a dynamic buffer is used when
the length is unknown, resulting in decreased performance.
if (response.ContentLength != -1)
state.DataLength = Convert.ToInt32(response.Content Length);
state.StaticBuffer = new byte[state.DataLength];
Search Nedrilad ::

Custom Search