473,322 Members | 1,421 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,322 software developers and data experts.

StreamReader.ReadToEnd

I'm curious - does StreamReader.ReadToEnd() handle chunk loading of
data or does it block until the whole stream is loaded? I've been use
to handling the buffer myself but I'm thinking maybe this is a quicker
way of doing it. In particular I want to ensure the UI doesn't hang
whilst loading, for example on a progress bar.

Thanks

Mar 7 '06 #1
4 5722
Chris S. wrote:
I'm curious - does StreamReader.ReadToEnd() handle chunk loading of
data or does it block until the whole stream is loaded?
It blocks until the whole stream is loaded - how else would it be able
to return anything?
I've been use
to handling the buffer myself but I'm thinking maybe this is a quicker
way of doing it. In particular I want to ensure the UI doesn't hang
whilst loading, for example on a progress bar.


If you want to stop the UI from hanging, you should do your IO in a
different thread.

Jon

Mar 7 '06 #2
And in terms of speed, is StreamReader.ReadToEnd() or reading byte by
byte yourself (and handling the buffering yourself) faster?

Mar 7 '06 #3
> And in terms of speed, is StreamReader.ReadToEnd() or reading byte by
byte yourself (and handling the buffering yourself) faster?


Unless Microsoft did a really botched up job of implementing ReadToEnd I'd
say that by default the implementation of ReadToEnd will be faster than reading
byte by byte.

However, if your goal is to read the rest of the file and process it then
it depends:

with your buffering solution, would you:

- fill the buffer, process it, then throw it away or reuse it?
- fill the buffer, then keep it and allocate a new buffer for the rest?

the difference would be if you were to process a really big file, larger
than your amount of available memory. With .ReadToEnd, you might end up swapping
memory blocks to disk, which is costly. If you process the file a buffer
at a time, you might not need to as the size of the file would be irrelevant
as you only keep a buffers worth in memory anyway.

--
Lasse Vågsæther Karlsen
http://usinglvkblog.blogspot.com/
mailto:la***@vkarlsen.no
PGP KeyID: 0x2A42A1C2
Mar 7 '06 #4
Surely both would use the same method? A temporary byte buffer[] and
the bucket to throw the bytes into. I'll do some tests with a 1mb file
(network and disk) when I have some free time, just for my interest.

Mar 8 '06 #5

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

1
by: andrewcw | last post by:
OK I am half way there - I can manipulate the stream without the byte issue like this - but is this the way to push the new values back into the stream & write out the stream without resorting to...
9
by: oafyuf | last post by:
Hi, I'm having performanbce issues with StreamReader and was wondering what I could do to improve it... The following takes around 3 seconds to process! The content of the response is: ...
2
by: Nad | last post by:
Hello All, I have been trying to get some sort of documantion on how StreamReader.ReadToEnd() finds out if the stream has ended and if anyone can read the following lines and tell me how to...
9
by: ShadowOfTheBeast | last post by:
Hi, I have got a major headache understanding streamReader and streamWriter relationship. I know how to use the streamreader and streamwriter independently. but how do you write out using the...
4
by: | last post by:
I am receiving xml via tcp/ip and want to save it into a msmq queue. when I use the StreamReader.ReadLine() it only reads one line of the stream. but my xml could be more than 1 line. when I use...
11
by: LucaJonny | last post by:
Hi, I've got a problem using StreamReader in VB.NET. I try to read a txt file that contains extended characters and theese are removed from the line that is being read. I've read a lot of...
2
by: rVo | last post by:
In a VB.Net application I create a new streamreader and use it's ReadToEnd function to read the contents of a htmlfile. Inside the file there are some signs like öéèêë..., these signs are not...
4
by: Hexman | last post by:
Code below ---- I've asked a similar question on this forum earlier. This is a slightly different situation. Previous Question ---- I'm trying to save some specific web pages to disk as...
1
by: Sladan | last post by:
Im trying to read a xml-file with a StreamReader. For the moment I'm using the following code. streamReader = new StreamReader(stream, System.Text.Encoding.Default); string feedData =...
0
by: ryjfgjl | last post by:
ExcelToDatabase: batch import excel into database automatically...
0
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, we are pleased to welcome back...
1
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, we are pleased to welcome back...
0
by: Vimpel783 | last post by:
Hello! Guys, I found this code on the Internet, but I need to modify it a little. It works well, the problem is this: Data is sent from only one cell, in this case B5, but it is necessary that data...
0
by: jfyes | last post by:
As a hardware engineer, after seeing that CEIWEI recently released a new tool for Modbus RTU Over TCP/UDP filtering and monitoring, I actively went to its official website to take a look. It turned...
0
by: ArrayDB | last post by:
The error message I've encountered is; ERROR:root:Error generating model response: exception: access violation writing 0x0000000000005140, which seems to be indicative of an access violation...
1
by: PapaRatzi | last post by:
Hello, I am teaching myself MS Access forms design and Visual Basic. I've created a table to capture a list of Top 30 singles and forms to capture new entries. The final step is a form (unbound)...
1
by: Defcon1945 | last post by:
I'm trying to learn Python using Pycharm but import shutil doesn't work
1
by: Shællîpôpï 09 | last post by:
If u are using a keypad phone, how do u turn on JavaScript, to access features like WhatsApp, Facebook, Instagram....

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.