FileStream.EndRead(IAsyncResult) FileStream.EndRead(IAsyncResult) FileStream.EndRead(IAsyncResult) FileStream.EndRead(IAsyncResult) Method

Definición

Espera a que se complete la operación asincrónica de lectura que se encuentra pendiente.Waits for the pending asynchronous read operation to complete. (Considere usar ReadAsync(Byte[], Int32, Int32, CancellationToken) en su lugar).(Consider using ReadAsync(Byte[], Int32, Int32, CancellationToken) instead.)

public:
 override int EndRead(IAsyncResult ^ asyncResult);
public override int EndRead (IAsyncResult asyncResult);
override this.EndRead : IAsyncResult -> int
Public Overrides Function EndRead (asyncResult As IAsyncResult) As Integer

Parámetros

asyncResult
IAsyncResult IAsyncResult IAsyncResult IAsyncResult

Referencia a la solicitud asincrónica pendiente a la que se debe esperar.The reference to the pending asynchronous request to wait for.

Devoluciones

Número de bytes leídos de la secuencia, que se encuentra entre 0 y el número de bytes solicitado.The number of bytes read from the stream, between 0 and the number of bytes you requested. Las secuencias solo devuelven 0 al final de la secuencia; de lo contrario, se deben bloquear hasta que haya al menos 1 byte disponible.Streams only return 0 at the end of the stream, otherwise, they should block until at least 1 byte is available.

Excepciones

La secuencia está cerrada o se produjo un error interno.The stream is closed or an internal error has occurred.

Ejemplos

Este ejemplo de código forma parte de un ejemplo más extenso proporcionado para el FileStream(String, FileMode, FileAccess, FileShare, Int32, Boolean) constructor.This code example is part of a larger example provided for the FileStream(String, FileMode, FileAccess, FileShare, Int32, Boolean) constructor.

   static void EndReadCallback( IAsyncResult^ asyncResult )
   {
      State^ tempState = dynamic_cast<State^>(asyncResult->AsyncState);
      int readCount = tempState->FStream->EndRead( asyncResult );
      int i = 0;
      while ( i < readCount )
      {
         if ( tempState->ReadArray[ i ] != tempState->WriteArray[ i++ ] )
         {
            Console::WriteLine( "Error writing data." );
            tempState->FStream->Close();
            return;
         }
      }

      Console::WriteLine( "The data was written to {0} "
      "and verified.", tempState->FStream->Name );
      tempState->FStream->Close();
      
      // Signal the main thread that the verification is finished.
      tempState->ManualEvent->Set();
   }


public:

static void EndReadCallback(IAsyncResult asyncResult)
{
    State tempState = (State)asyncResult.AsyncState;
    int readCount = tempState.FStream.EndRead(asyncResult);

    int i = 0;
    while(i < readCount)
    {
        if(tempState.ReadArray[i] != tempState.WriteArray[i++])
        {
            Console.WriteLine("Error writing data.");
            tempState.FStream.Close();
            return;
        }
    }
    Console.WriteLine("The data was written to {0} and verified.",
        tempState.FStream.Name);
    tempState.FStream.Close();

    // Signal the main thread that the verification is finished.
    tempState.ManualEvent.Set();
}
Private Shared Sub EndReadCallback(asyncResult As IAsyncResult)
     Dim tempState As State = _
         DirectCast(asyncResult.AsyncState, State)
     Dim readCount As Integer = _
         tempState.FStream.EndRead(asyncResult)

     Dim i As Integer = 0
     While(i < readCount)
         If(tempState.ReadArray(i) <> tempState.WriteArray(i))
             Console.WriteLine("Error writing data.")
             tempState.FStream.Close()
             Return
         End If
         i += 1
     End While

     Console.WriteLine("The data was written to {0} and " & _
         "verified.", tempState.FStream.Name)
     tempState.FStream.Close()

     ' Signal the main thread that the verification is finished.
     tempState.ManualEvent.Set()
 End Sub

Comentarios

En .NET Framework 4 y versiones anteriores, tendrá que utilizar métodos como BeginRead y EndRead para implementar operaciones de archivos asincrónica.In the .NET Framework 4 and earlier versions, you have to use methods such as BeginRead and EndRead to implement asynchronous file operations. Estos métodos siguen estando disponibles en el .NET Framework 4.5.NET Framework 4.5 para admitir código heredado; sin embargo, los nuevos métodos asincrónicos, como ReadAsync, WriteAsync, CopyToAsync, y FlushAsync, ayuda implementa operaciones de archivo asincrónicas más fácilmente.These methods are still available in the .NET Framework 4.5.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 se debe llamar exactamente para cada llamada a BeginRead.EndRead must be called exactly for every call to BeginRead. No se puede terminar un proceso de lectura antes de comenzar otra lectura puede provocar un comportamiento no deseado, como el interbloqueo.Failing to end a read process before beginning another read can cause undesirable behavior such as deadlock.

Este método invalida EndRead.This method overrides EndRead.

EndRead se puede llamar en cada IAsyncResult desde BeginRead.EndRead can be called on every IAsyncResult from BeginRead. Una llamada a EndRead le indica cuántos bytes se leyeron de la secuencia.Calling EndRead tells you how many bytes were read from the stream. EndRead se bloqueará hasta que se ha completado la operación de E/S.EndRead will block until the I/O operation has completed.

Se aplica a

Consulte también: