I am using WebClient.OpenReadAsync method to download data from a web server on Windows Phone 7. At some point, OpenReadCompleted event is raised and I am given a stream that I can use to read the data.
Can I assume that the data is already downloaded when this happens? I.e. reading the stream to end will be a local operation and will not involve any more network access? Or will reading the stream actually trigger downloading the data?
If the data is already downloaded, where is it stored? What if the data is massive and won’t fit anywhere, and I only want to read a small part of it?
I cannot find any information about it in the documentation.
No, you can’t assume that. This event is raised when an asynchronous operation to open a stream containing a resource completes. Once you start reading the stream, this stream will be read from the network socket resulting in a network I/O operation.
Nowhere, no data is ever downloaded at the moment this event is raised. So if the data returned by the server is huge, it’s up to you to read it in chunks in memory and write it on some other Stream (like a file or database or something).