Game Development Reference
In-Depth Information
}
else
{
state.FixedSizeBuffer = false;
state.DynamicBuffer = new List<byte>(bufferSize);
}
Retrieve the response object for the request so that data can now be read from the
stream.
Stream responseStream = response.GetResponseStream();
state.ResponseStream = responseStream;
Begin reading stream data asynchronously.
IAsyncResult readResult
= responseStream.BeginRead(state.ProcessBuffer,
0,
bufferSize,
new AsyncCallback(ReadCallback),
state);
}
The following callback is used when an asynchronous data read occurs.
private void ReadCallback(IAsyncResult asyncResult)
{
Pull the asynchronous state object out of the result object.
AsyncFileDownloadState state =
(AsyncFileDownloadState)asyncResult.AsyncState;
Retrieve the ResponseStream from the state object that was set in the ResponseCallback .
Stream responseStream = state.ResponseStream;
Check if there is any more data to read.
int bytesRead = responseStream.EndRead(asyncResult);
if (bytesRead > 0)
{
Copy the temporary data buffer into the appropriate data buffer that holds the
final data.
if (state.FixedSizeBuffer)
{
Search Nedrilad ::




Custom Search