Game Development Reference
In-Depth Information
The following is a constant that describes the temporary buffer size of incoming
data when the content length is unknown.
private const int bufferSize = 1024;
The following object is used to signal that the download is complete. ManualResetEvent
allows threads to communicate with each other; it is typically used when one
thread must be completed before others can proceed.
public ManualResetEvent completeEvent = new ManualResetEvent(false);
The following method downloads the data of a file pointed to by the address
string. The specified callback is used to report progress status.
public byte[] DownloadFile(string address,
AsyncDownloadProgressHandler callback)
{
Uri addressUri = new Uri(address);
return DownloadFile(addressUri, callback);
}
The following method downloads the data of a file pointed to by the Uri. The spec-
ified callback is used to report progress status.
public byte[] DownloadFile(Uri address, AsyncDownloadProgressHandler callback)
{
Set the complete event state to un-signaled.
completeEvent.Reset();
Create a new HttpWebRequest object by passing in the address to the resource.
Passing in a file:// address will result in a FileWebRequest object being created,
working transparently with the existing code because of the protocol-agnostic
model used.
WebRequest request = WebRequest.Create(address);
Instantiate a new asynchronous state object and reference the request for later use.
AsyncFileDownloadState state = new AsyncFileDownloadState();
state.Request = request;
Set the progress update callback on the state object.
state.ProgressUpdate += callback;
Search Nedrilad ::




Custom Search