PDA

Click to See Complete Forum and Search --> : [2.0] Infinite loop tcpclient


cx323
Jul 28th, 2006, 01:57 PM
private void DoRead(IAsyncResult ar)
{
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;

I fixed it i just needed to get rid of doevents.

mendhak
Jul 29th, 2006, 06:03 PM
Couldn't you use an HttpWebRequest?

JenniferBabe
Jul 29th, 2006, 11:31 PM
I don't know if this might help, but it's because byteread is never less than 1. I got that problem once and when I changed it to bytesRead <1024, it worked and is still working today. Probaly it might help I dont know. - Jennifer