StreamReader.Peek Timeout

  • Thread starter Thread starter Bishop
  • Start date Start date
B

Bishop

I'm trying to use the StreamReader to read messages from a newsgroup but
after downloading several messages it will get stuck on the
streamReader.Peek line and never timeout (or at least not after 12 hours)



Any suggestions on how to timeout?
 
Hello, Bishop!

B> I'm trying to use the StreamReader to read messages from a newsgroup
B> but
B> after downloading several messages it will get stuck on the
B> streamReader.Peek line and never timeout (or at least not after 12
B> hours)

B> Any suggestions on how to timeout?

Give us code sample, where you read messages.

--
Regards, Vadym Stetsyak
www: http://vadmyst.blogspot.com
 
Dim output As String

streamReader = New System.IO.StreamReader(networkStream)

Do While streamReader.Peek > 0

If output <> "" Then output = output & vbCrLf

output = output & streamReader.ReadLine

Loop

Return output
 
Hello, Bishop!

B> Dim output As String

B> streamReader = New System.IO.StreamReader(networkStream)

B> Do While streamReader.Peek > 0

B> If output <> "" Then output = output & vbCrLf

B> output = output & streamReader.ReadLine

B> Loop

B> Return output


I suggest, that you use Network stream directly. Here's sample in C#
byte[] data = new byte[1024];
int count;
output = string.Empty;
while ( (count = networkStream.Read(data, 0, data.Length)) != 0 )
{
output += Encoding.ASCII.GetString(data, 0, count);
//another code here
}
--
Regards, Vadym Stetsyak
www: http://vadmyst.blogspot.com
 
When I do it that way, the function returns empty strings.

So there is no way to set a timeout?
 
Bishop said:
When I do it that way, the function returns empty strings.

So there is no way to set a timeout?


NetworkStream.ReadTimeout and .WriteTimeout let you set the timeout of the
stream. Having set the timeout (the default in Infinite), your stream
reader should throw an IOException when the timeout occurs.

-cd
 
Works great, Thanks!


Carl Daniel said:
NetworkStream.ReadTimeout and .WriteTimeout let you set the timeout of the
stream. Having set the timeout (the default in Infinite), your stream
reader should throw an IOException when the timeout occurs.

-cd
 
Back
Top