H
Hilton
Hi,
I have a while (true) look reading bytes from an
httpresponse.GetResponseStream() and writing them to a file. If the user
presses a Cancel button, I do a "break", the loop exits, then the app gets
stuck on "responsestream.Close ();" which reads the entire rest of the
stream before closing! This part has nothing to do with the for-loop, the
app just sits in the Close(). How can I get the app to just be done with
the stream, close it and move on without reading in the megabytes that might
follow? Why is Close() reading the rest of the stream?
Any suggestions are appreciated? I have tried various things, most cause
exceptions and/or stock future downloads from working (not sure why about
this one either). FWIW: The code runs perfectly on the desktop; i.e. the
Close() does not download the rest of the stream. Is this (another) really
bad CF bug or am I doing something very wrong? I hope I'm wrong.
Code is below...
Thanks,
Hilton
-----------
using (FileStream fs = new FileStream (tmpFilename,
FileMode.Create, FileAccess.Write))
{
bool checkedEqual = false;
// Data buffer
byte[] buffer = new byte [BUFFER_SIZE];
// Copy all the bytes from the HTTP stream to the
file
do
{
int bytesRead = responsestream.Read (buffer, 0,
BUFFER_SIZE);
// End of stream?
if (bytesRead == 0)
{
break;
}
// If not, write the bytes we have
fs.Write (buffer, 0, bytesRead);
bytesDownloaded += bytesRead;
// Fire off the progress events.
if (peh != null)
{
ProgressEventArgs pea = new
ProgressEventArgs (dataSize, bytesDownloaded);
peh (null, pea);
if (pea.Cancel)
{
break;
}
}
} while (true);
}
// This Close() reads the rest of the
stream!!!!!!!!!!!!!!!!!!!!!!!!!!!
responsestream.Close ();
I have a while (true) look reading bytes from an
httpresponse.GetResponseStream() and writing them to a file. If the user
presses a Cancel button, I do a "break", the loop exits, then the app gets
stuck on "responsestream.Close ();" which reads the entire rest of the
stream before closing! This part has nothing to do with the for-loop, the
app just sits in the Close(). How can I get the app to just be done with
the stream, close it and move on without reading in the megabytes that might
follow? Why is Close() reading the rest of the stream?
Any suggestions are appreciated? I have tried various things, most cause
exceptions and/or stock future downloads from working (not sure why about
this one either). FWIW: The code runs perfectly on the desktop; i.e. the
Close() does not download the rest of the stream. Is this (another) really
bad CF bug or am I doing something very wrong? I hope I'm wrong.
Code is below...
Thanks,
Hilton
-----------
using (FileStream fs = new FileStream (tmpFilename,
FileMode.Create, FileAccess.Write))
{
bool checkedEqual = false;
// Data buffer
byte[] buffer = new byte [BUFFER_SIZE];
// Copy all the bytes from the HTTP stream to the
file
do
{
int bytesRead = responsestream.Read (buffer, 0,
BUFFER_SIZE);
// End of stream?
if (bytesRead == 0)
{
break;
}
// If not, write the bytes we have
fs.Write (buffer, 0, bytesRead);
bytesDownloaded += bytesRead;
// Fire off the progress events.
if (peh != null)
{
ProgressEventArgs pea = new
ProgressEventArgs (dataSize, bytesDownloaded);
peh (null, pea);
if (pea.Cancel)
{
break;
}
}
} while (true);
}
// This Close() reads the rest of the
stream!!!!!!!!!!!!!!!!!!!!!!!!!!!
responsestream.Close ();