Tcpclient infinite loop
{
int BytesRead;
try
{
BytesRead = client.GetStream().EndRead(ar);
if ((BytesRead < 1))
{
Finished = true;
return;
}
strHTML += Encoding.ASCII.GetString(readBuffer, 0, (BytesRead - 2));
BytesRead = 0;
client.GetStream().BeginRead(readBuffer, 0, READ_BUFFER_SIZE, new System.AsyncCallback(this.DoRead), null);
}
catch (Exception)
{
// Future Handle
}
}
I call it like this:
client.GetStream().BeginRead(readBuffer, 0, READ_BUFFER_SIZE, new AsyncCallback(DoRead), null);
while (Finished != true)
{
Application.DoEvents();
}
Finished = false;
The problem is that once it's finished reading the data it continuosly jumps from the last beginread to the end of the function. I ran it through in debug mode and once it reads the last bit of data BytesRead somehow gets stuck at 255 and it loops continusosly from
client.GetStream().BeginRead(readBuffer, 0, READ_BUFFER_SIZE, new System.AsyncCallback(this.DoRead), null); to the last }.
I tried putting client.GetStream().DataAvailable, but then if there is a small amount of time where this isn't any data it stops.
Thanks for any help

