Begins an asynchronous read operation. (Consider using ReadAsync instead; see the Remarks section.)
Assembly: mscorlib (in mscorlib.dll)
[<HostProtectionAttribute(SecurityAction.LinkDemand, ExternalThreading = true)>] abstract BeginRead : array:byte * offset:int * numBytes:int * userCallback:AsyncCallback * stateObject:Object -> IAsyncResult [<HostProtectionAttribute(SecurityAction.LinkDemand, ExternalThreading = true)>] override BeginRead : array:byte * offset:int * numBytes:int * userCallback:AsyncCallback * stateObject:Object -> IAsyncResult
- Type: System.Byte
The buffer to read data into.
- Type: System.Int32
The byte offset in array at which to begin reading.
- Type: System.Int32
The maximum number of bytes to read.
- Type: System.AsyncCallback
The method to be called when the asynchronous read operation is completed.
- Type: System.Object
A user-provided object that distinguishes this particular asynchronous read request from other requests.
Return ValueType: System.IAsyncResult
An object that references the asynchronous read.
In the .NET Framework 4 and earlier versions, you have to use methods such as and EndRead to implement asynchronous file operations. These methods are still available in the .NET Framework 4.5 to support legacy code; however, the new async methods, such as ReadAsync, WriteAsync, CopyToAsync, and FlushAsync, help you implement asynchronous file operations more easily.
EndRead must be called exactly once for every call to . Failing to end a read process before beginning another read can cause undesirable behavior such as deadlock.
FileStream provides two different modes of operation: synchronous I/O and asynchronous I/O. While either can be used, the underlying operating system resources might allow access in only one of these modes. By default, FileStream opens the operating system handle synchronously. In Windows, this slows down asynchronous methods. If asynchronous methods are used, use the FileStream(String, FileMode, FileAccess, FileShare, Int32, Boolean) constructor.
If a stream is closed or you pass an invalid argument, exceptions are thrown immediately from . Errors that occur during an asynchronous read request, such as a disk failure during the IO request, occur on the thread pool thread and become visible upon a call to EndRead.
Multiple simultaneous asynchronous requests render the request completion order uncertain.
For a list of common file and directory operations, see Common I/O Tasks.
The HostProtectionAttribute attribute applied to this type or member has the following Resources property value: ExternalThreading. The HostProtectionAttribute does not affect desktop applications (which are typically started by double-clicking an icon, typing a command, or entering a URL in a browser). For more information, see the HostProtectionAttribute class or SQL Server Programming and Host Protection Attributes.