Game Development Reference
In-Depth Information
The following code shows this.
AsyncFileDownloadRequest request = new AsyncFileDownloadRequest();
// Specify the address of the file to download
request.Address = new Uri(“http://yourdomain/thefile”);
// Assign a delegate to handle download complete events
request.DownloadComplete
+= new AsyncDownloadCompleteHandler(DownloadCompleteCallback);
// Assign a delegate to handle progress update events
request.ProgressUpdate
+= new AsyncDownloadProgressHandler(DownloadProgressCallback);
// Request the file
request.Initiate();
Conclusion
This chapter discussed the HttpWebRequest and HttpWebResponse classes, and then
presented a reusable solution using these classes to asynchronously download files
off a network or Internet server.
The Companion Web site has the full source code to the download system, includ-
ing a simple demo that shows how to use the system. Figure 29.1 shows the main
interface of the provided example.
As mentioned earlier, there are a number of ways that files can be downloaded
asynchronously from a network location, but the solution presented in this chap-
ter fully utilizes the built-in functionality of the .NET Class Framework.
Figure 29.1 Screenshot of the demo application on the Companion Web site.
Search Nedrilad ::




Custom Search