C# Programming
06-14-2011, 06:51 AM
I send web requests and read data web response:
using (Stream stream = response.GetResponseStream()) { Data = new byte[response.ContentLength]; int offset = 0; int count = (int)response.ContentLength; int nBytes = 0; int nTotalBytes = 0; while ((nBytes = stream.Read(Data, offset, count)) > 0) { offset += nBytes; count -= nBytes; nTotalBytes += nBytes; } }
If internet connection is suddenyl down Read() function blocks forever.
Is there a way to avoid it using the same Read() method?
<div class="signature">
using (Stream stream = response.GetResponseStream()) { Data = new byte[response.ContentLength]; int offset = 0; int count = (int)response.ContentLength; int nBytes = 0; int nTotalBytes = 0; while ((nBytes = stream.Read(Data, offset, count)) > 0) { offset += nBytes; count -= nBytes; nTotalBytes += nBytes; } }
If internet connection is suddenyl down Read() function blocks forever.
Is there a way to avoid it using the same Read() method?
<div class="signature">