PipeStream.Read Method (Byte[], Int32, Int32)
Reads a block of bytes from a stream and writes the data to a specified buffer.
Assembly: System.Core (in System.Core.dll)
[<SecurityCriticalAttribute>] override Read : buffer:byte[] * offset:int * count:int -> int
Parameters
- buffer
-
Type:
System.Byte[]
When this method returns, contains the specified byte array with the values between offset and (offset + count - 1) replaced by the bytes read from the current source.
- offset
-
Type:
System.Int32
The byte offset in the buffer array at which the bytes that are read will be placed.
- count
-
Type:
System.Int32
The maximum number of bytes to read.
Return Value
Type: System.Int32The total number of bytes that are read into buffer. This might be less than the number of bytes requested if that number of bytes is not currently available, or 0 if the end of the stream is reached.
| Exception | Condition |
|---|---|
| ArgumentNullException | buffer is null. |
| ArgumentOutOfRangeException | offset is less than 0. -or- count is less than 0. |
| ArgumentException | count is greater than the number of bytes available in buffer. |
| ObjectDisposedException | The pipe is closed. |
| NotSupportedException | The pipe does not support read operations. |
| InvalidOperationException | The pipe is disconnected, waiting to connect, or the handle has not been set. |
| IOException | Any I/O error occurred. |
Use the CanRead property to determine whether the current PipeStream object supports read operations.
Calling the Read method blocks until count bytes are read or the end of the stream is reached. For asynchronous read operations, see BeginRead and EndRead.
The following example creates an anonymous pipe client and pipe server. The pipe server uses the Read method to read a series of bytes from the pipe client as a validation code. Both the pipe client and the pipe server are part of the same example. The server portion of the example creates a client process and passes it an anonymous pipe handle as an argument.
Available since 3.5