Home All Groups Group Topic Archive Search About

StreamReader.Peek Timeout

Author
27 Sep 2006 3:01 AM
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?

Author
27 Sep 2006 9:08 AM
Vadym Stetsyak
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
Author
27 Sep 2006 11:42 AM
Bishop
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





Show quote
"Vadym Stetsyak" <vady***@ukr.net> wrote in message
news:e5XzEQh4GHA.3604@TK2MSFTNGP03.phx.gbl...
> 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
Author
27 Sep 2006 12:24 PM
Vadym Stetsyak
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
Author
27 Sep 2006 9:53 PM
Bishop
When I do it that way, the function returns empty strings.

So there is no way to set a timeout?



Show quote
"Vadym Stetsyak" <vady***@ukr.net> wrote in message
news:%23lEml9i4GHA.3396@TK2MSFTNGP04.phx.gbl...
> 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
Author
27 Sep 2006 10:47 PM
Carl Daniel [VC++ MVP]
"Bishop" <nospam@nospam.com> wrote in message
news:%23oBtZ9n4GHA.3452@TK2MSFTNGP05.phx.gbl...
> 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
Author
28 Sep 2006 12:35 AM
Bishop
Works great, Thanks!


Show quote
"Carl Daniel [VC++ MVP]" <cpdaniel_remove_this_and_nospam@mvps.org.nospam>
wrote in message news:uSJOybo4GHA.3444@TK2MSFTNGP02.phx.gbl...
> "Bishop" <nospam@nospam.com> wrote in message
> news:%23oBtZ9n4GHA.3452@TK2MSFTNGP05.phx.gbl...
>> 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
>
>

AddThis Social Bookmark Button