473,325 Members | 2,774 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,325 software developers and data experts.

StreamReader/ReadBlock

The documentation has the following remark for the ReadBlock method of the
StreamReader: "The method blocks until either count characters are read, or
all characters have been read".

What kind of blocking are they referring to? Are they referring to the
BaseStream being blocked so that no other process can read or write to it?

For example, in the case of a StreamReader based on FileStream, does this
mean that the actual file on the hard drive will be blocked for read, write
etc? Or does it mean that the stream on memory is the one that is blocked?
Is the blocking occurring for only the bytes after the FileStream position?
Am I totally not getting it?

Thanks.
Nov 16 '05 #1
3 11135
Rene <no****@nospam.com> wrote:
The documentation has the following remark for the ReadBlock method of the
StreamReader: "The method blocks until either count characters are read, or
all characters have been read".

What kind of blocking are they referring to? Are they referring to the
BaseStream being blocked so that no other process can read or write to it?
No, they're referring to the method not returning. It doesn't change
whether or not anything else can read or write to the stream.

Basically, it means that you can rely on StreamReader.ReadBlock not
returning until either it's read as much as you've asked it to, or it's
reached the end of the stream.
For example, in the case of a StreamReader based on FileStream, does this
mean that the actual file on the hard drive will be blocked for read, write
etc? Or does it mean that the stream on memory is the one that is blocked?
Is the blocking occurring for only the bytes after the FileStream position?
Am I totally not getting it?


I think you're totally missing it, I'm afraid :)

--
Jon Skeet - <sk***@pobox.com>
http://www.pobox.com/~skeet
If replying to the group, please do not mail me too
Nov 16 '05 #2
Hey John:

Believe or not, that was the first thing that occurred to me but when I
thought of that it didn't compile in my head!

I mean, most of the function calls to objects won't return until the work is
done (that's kind of expected behaviors in my opinion). Inside my little
head I thought that the Read() method would not return until everything was
read and that the ReadBlock was not doing what you just said because if that
was the case, it would have been named something like
ReadAsynchronous(delegate FunctionToCallWhenFinishReading).

Oh well, thanks for clearing every thing.

"Jon Skeet [C# MVP]" <sk***@pobox.com> wrote in message
news:MP************************@msnews.microsoft.c om...
Rene <no****@nospam.com> wrote:
The documentation has the following remark for the ReadBlock method of
the
StreamReader: "The method blocks until either count characters are read,
or
all characters have been read".

What kind of blocking are they referring to? Are they referring to the
BaseStream being blocked so that no other process can read or write to
it?


No, they're referring to the method not returning. It doesn't change
whether or not anything else can read or write to the stream.

Basically, it means that you can rely on StreamReader.ReadBlock not
returning until either it's read as much as you've asked it to, or it's
reached the end of the stream.
For example, in the case of a StreamReader based on FileStream, does this
mean that the actual file on the hard drive will be blocked for read,
write
etc? Or does it mean that the stream on memory is the one that is
blocked?
Is the blocking occurring for only the bytes after the FileStream
position?
Am I totally not getting it?


I think you're totally missing it, I'm afraid :)

--
Jon Skeet - <sk***@pobox.com>
http://www.pobox.com/~skeet
If replying to the group, please do not mail me too

Nov 16 '05 #3
Rene <no****@nospam.com> wrote:
Believe or not, that was the first thing that occurred to me but when I
thought of that it didn't compile in my head!

I mean, most of the function calls to objects won't return until the work is
done (that's kind of expected behaviors in my opinion). Inside my little
head I thought that the Read() method would not return until everything was
read and that the ReadBlock was not doing what you just said because if that
was the case, it would have been named something like
ReadAsynchronous(delegate FunctionToCallWhenFinishReading).

Oh well, thanks for clearing every thing.


In this case it's not a case of potentially being asynchronous - it's a
case of potentially returning when only some of what you requested has
been read, and stopping there. That's what Stream.Read does, for
example.

--
Jon Skeet - <sk***@pobox.com>
http://www.pobox.com/~skeet
If replying to the group, please do not mail me too
Nov 16 '05 #4

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

Similar topics

2
by: Keith Kingsley | last post by:
I'm using a StreamReader to read in several lines from an ASCII file. I'd like to know the StreamReader's "true" position-- that is, the number of bytes into the file that the StreamReader has...
3
by: Arno | last post by:
Hi, I'm using TcpClient for communication between two PC running a small piece of software. The protocol used has been designed internally and is HTTP similar (command line, headers, body). A...
4
by: Max | last post by:
I'm using StreamReader.ReadToEnd() to populate and string from a file and then display it as a literal on my web site. The problem is I'm losing all the special characters like Æ,Ø, and Å that...
5
by: Shad | last post by:
Hello, I am developping an application that needs to launch several asp scripts at the same time, to I have created threads which use one streamreader each. This works fine, except that I need...
2
by: dave | last post by:
Hi. I am tring to read from random parts of an SDF file using a stream reader. I know each line in my file is 30 chars long so I know where in the file I want to go to read a specific record. The...
9
by: lord.zoltar | last post by:
Hi, I'm having some trouble with a StreamReader. I use a System.IO.StreamReader to read a text file and then print it. If the user has selected a range of pages starting past the first page, I...
3
by: Arpan | last post by:
A file can be read using only the StreamReader object like this: Dim sReader As StreamReader sReader = New StreamReader(Server.MapPath("File1.txt")) While(sReader.Peek -1)...
4
by: Mike R | last post by:
Hi All, I'm trying to read a file that has the following format, its a variable record file, the first byte determines how to process the rest. byte 1 = either 0,1,2,3 4 bytes = size of the...
0
by: rajana | last post by:
Dear All, We have Ansi file with german characters (Ä / Ø) , We are using Streamreader to read the contents of the file. But Readline() not able to read the German characters. We tried all...
0
by: DolphinDB | last post by:
Tired of spending countless mintues downsampling your data? Look no further! In this article, you’ll learn how to efficiently downsample 6.48 billion high-frequency records to 61 million...
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: 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: CloudSolutions | last post by:
Introduction: For many beginners and individual users, requiring a credit card and email registration may pose a barrier when starting to use cloud servers. However, some cloud server providers now...
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....
0
by: Faith0G | last post by:
I am starting a new it consulting business and it's been a while since I setup a new website. Is wordpress still the best web based software for hosting a 5 page website? The webpages will be...

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.