|
dev
newsgroups
|
|||||||||||||||||||||||
|
|||||||||||||||||||||||
StreamReader.Peek TimeoutI'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. 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 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 } 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 "Bishop" <nospam@nospam.com> wrote in message NetworkStream.ReadTimeout and .WriteTimeout let you set the timeout of the 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? stream. Having set the timeout (the default in Infinite), your stream reader should throw an IOException when the timeout occurs. -cd 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 > > |
|||||||||||||||||||||||