Begins an asynchronous read.
Assembly: mscorlib (in mscorlib.dll)
'Declaration <HostProtectionAttribute(SecurityAction.LinkDemand, ExternalThreading := True)> _ Public Overrides Function BeginRead ( _ array As Byte(), _ offset As Integer, _ numBytes As Integer, _ userCallback As AsyncCallback, _ stateObject As Object _ ) As IAsyncResult 'Usage Dim instance As FileStream Dim array As Byte() Dim offset As Integer Dim numBytes As Integer Dim userCallback As AsyncCallback Dim stateObject As Object Dim returnValue As IAsyncResult returnValue = instance.BeginRead(array, _ offset, numBytes, userCallback, stateObject)
- 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.
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.
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.
Windows Mobile for Pocket PC, Windows Mobile for Smartphone, Windows CE Platform Note: In .NET Compact Framework applications, this method is supported, but it is reserved for future use. Using this method will raise a NotSupportedException until it becomes available in a future release.
This code example is part of a larger example provided for the FileStream(String, FileMode, FileAccess, FileShare, Int32, Boolean) constructor.
Private Shared Sub EndWriteCallback(asyncResult As IAsyncResult) Dim tempState As State = _ DirectCast(asyncResult.AsyncState, State) Dim fStream As FileStream = tempState.FStream fStream.EndWrite(asyncResult) ' Asynchronously read back the written data. fStream.Position = 0 asyncResult = fStream.BeginRead( _ tempState.ReadArray, 0 , tempState.ReadArray.Length, _ AddressOf EndReadCallback, tempState) ' Concurrently do other work, such as ' logging the write operation. End Sub
Windows 7, Windows Vista, Windows XP SP2, Windows XP Media Center Edition, Windows XP Professional x64 Edition, Windows XP Starter Edition, Windows Server 2008 R2, Windows Server 2008, Windows Server 2003, Windows Server 2000 SP4, Windows Millennium Edition, Windows 98
The .NET Framework and .NET Compact Framework do not support all versions of every platform. For a list of the supported versions, see .NET Framework System Requirements.