Home | Contact Us | FAQ | Search & Site Map | Link to Us
Sign In | Join | Other 45 Sites in Network
HomeAnnouncementsFree MagazinesWhite PapersSubmit Content
Discussion GroupsASP.NETWindows FormsLanguages.NET FrameworkVisual Studio.NET
Articles.NET FrameworkASP.NETToolsWindows Forms
.NET DirectoryOpen Source ProjectsUser GroupsWeb Resources
Related Topics
Visual Basic 6SQL ServerMS AccessOther DB ProductsMS Server ProductsMore Topics ...

.NET Forum / .NET Framework / New Users / September 2006

Tip: Looking for answers? Try searching our database.

StreamReader.Peek Timeout

Thread view: 
Enable EMail Alerts  Start New Thread
Thread rating: 
Bishop - 27 Sep 2006 04:01 GMT
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?
Vadym Stetsyak - 27 Sep 2006 10:08 GMT
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
Bishop - 27 Sep 2006 12:42 GMT
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!
>
[quoted text clipped - 11 lines]
> Regards, Vadym Stetsyak
> www: http://vadmyst.blogspot.com
Vadym Stetsyak - 27 Sep 2006 13:24 GMT
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 - 27 Sep 2006 22:53 GMT
When I do it that way, the function returns empty strings.

So there is no way to set a timeout?

> Hello, Bishop!
>
[quoted text clipped - 24 lines]
> Regards, Vadym Stetsyak
> www: http://vadmyst.blogspot.com
Carl Daniel [VC++ MVP] - 27 Sep 2006 23:47 GMT
> 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
Bishop - 28 Sep 2006 01:35 GMT
Works great, Thanks!

>> When I do it that way, the function returns empty strings.
>>
[quoted text clipped - 5 lines]
>
> -cd

Free Magazines

Get these publications absolutely FREE for up to 12 months. There are no hidden fees and no obligation. Simply choose a title, complete the application form and submit it. Read more ...

Oracle MagazineNetwork ComputingComputer WorldBio-IT WorldeWeekInformation WeekInfosecurity
 
Sign In
Join
My Latest Posts
My Monitored Threads
My Blog
My Photo Gallery
My Profile
My Homepage

Start New Thread
Enable EMail Alerts
Rate this Thread



©2008 Advenet LLC   Privacy Policy - Terms of Use
This website includes both content owned or controlled by Advenet as well as content owned or controlled by third parties.