Game Development Reference
Launch an asynchronous request to access a web resource.
IAsyncResult result =
state) as IAsyncResult;
Wait for the complete event to be set so that the data is not returned until the call-
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];