Windows Mobile 6.5 (C # .net cf 3.5) download file gets stuck in Stream Read
I have the following method which is used to download a file. It works great if the internet connection doesn't drop during the download process. In this case, it gets stuck in readStream read (i.e. in len = receiveStream.Read (buffer, 0, buffer.Length). It doesn't continue or throws an exception, it just seems to be stuck inside there forever. I set timeouts to 10 seconds and catch them above Am I doing something wrong or is there something missing?
I've also tried using asynchronous methods (BeginGetResponse, BeginRead, etc.) and they get stuck too.
I tested this on both a professional Windows Mobile 6 emulator and a Windows mobile device.
private void DownloadFile(string url, string filename)
{
HttpWebRequest request = (HttpWebRequest)WebRequest.Create(url);
request.Timeout = 10000;
request.ReadWriteTimeout = 10000;
using (HttpWebResponse response = (HttpWebResponse)request.GetResponse())
{
using (Stream receiveStream = response.GetResponseStream())
{
long size = response.ContentLength;
using (Stream file = File.OpenWrite(filename))
{
byte[] buffer = new byte[8 * 1024];
int len;
while ((len = receiveStream.Read(buffer, 0, buffer.Length)) > 0)
{
file.Write(buffer, 0, len);
total += len;
UpdateDownloadState(total, size);
}
}
}
}
}
thank
+3
source to share
No one has answered this question yet
See similar questions:
or similar: