Game Development Reference
In-Depth Information
Array.Copy(state.ProcessBuffer,
0,
state.StaticBuffer,
state.BytesRead,
bytesRead);
}
else
{
byte[] data = new byte[bytesRead];
Array.Copy(state.ProcessBuffer, 0, data, 0, bytesRead);
state.DynamicBuffer.AddRange(data);
}
state.BytesRead += bytesRead;
Notify any callbacks attached to the progress update event.
if (state.ProgressUpdate != null)
state.ProgressUpdate(state.BytesRead, state.DataLength);
Call another data read cycle until there are no more bytes to read.
IAsyncResult readResult
= responseStream.BeginRead(state.ProcessBuffer,
0,
bufferSize,
new AsyncCallback(ReadCallback),
state);
}
else
{
All the data has been downloaded, so we can now close the response stream and
signal the complete event.
responseStream.Close();
completeEvent.Set();
}
}
}
Sample Usage
Using the asynchronous download system is very easy. Simply specify the resource
address, and bind the two callbacks to handle progress updates and the download
complete event. After which, call the Initiate() method to begin downloading.
Search Nedrilad ::




Custom Search