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

정의

보류 중인 비동기 읽기 작업이 완료되기를 기다립니다.Waits for the pending asynchronous read operation to complete. 대신 ReadAsync(Byte[], Int32, Int32, CancellationToken)를 사용하세요.(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

매개 변수

asyncResult
IAsyncResult IAsyncResult IAsyncResult IAsyncResult

대기할 보류 중인 비동기 요청에 대한 참조입니다.The reference to the pending asynchronous request to wait for.

반환

0과 요청한 바이트 수 사이의 스트림에서 읽은 바이트 수입니다.The number of bytes read from the stream, between 0 and the number of bytes you requested. 스트림은 스트림의 끝에서 0만을 반환하며 그렇지 않으면 최소한 1바이트를 사용할 수 있을 때까지 차단됩니다.Streams only return 0 at the end of the stream, otherwise, they should block until at least 1 byte is available.

예외

이 클래스에 대해 IAsyncResult를 호출하여 이 BeginRead(Byte[], Int32, Int32, AsyncCallback, Object) 개체가 만들어지지 않은 경우This IAsyncResult object was not created by calling BeginRead(Byte[], Int32, Int32, AsyncCallback, Object) on this class.

스트림이 닫혔거나 내부 오류가 발생했습니다.The stream is closed or an internal error has occurred.

예제

이 코드 예제는에 대해 제공 된 큰 예제의 일부는 FileStream(String, FileMode, FileAccess, FileShare, Int32, Boolean) 생성자입니다.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

설명

.NET Framework 4 및 이전 버전에서와 같은 메서드를 사용 해야 BeginReadEndRead 비동기 파일 작업을 구현 합니다.In the .NET Framework 4 and earlier versions, you have to use methods such as BeginRead and EndRead to implement asynchronous file operations. 그러나 이러한 메서드는에서 계속 제공 합니다 .NET Framework 4.5.NET Framework 4.5 레거시 코드를 지원 하기 위해 새로운 비동기 메서드를 같은 ReadAsync, WriteAsync, CopyToAsync, 및 FlushAsync, 비동기 파일 작업을 보다 쉽게 구현 하는 도움말.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 호출할 때마다 한 번씩 호출 해야 BeginRead합니다.EndRead must be called exactly for every call to BeginRead. 다른 읽기를 시작 하기 전에 읽기 프로세스를 종료 하지 못하면 교착 상태 같은 바람직하지 않은 동작이 발생할 수 있습니다.Failing to end a read process before beginning another read can cause undesirable behavior such as deadlock.

이 메서드는 EndRead를 재정의합니다.This method overrides EndRead.

EndRead 호출할 수 마다 IAsyncResult 에서 BeginRead합니다.EndRead can be called on every IAsyncResult from BeginRead. 호출 EndRead 스트림에서 읽은 바이트 수는 방법을 알려 줍니다.Calling EndRead tells you how many bytes were read from the stream. EndRead I/O 작업이 완료 될 때까지 차단 됩니다.EndRead will block until the I/O operation has completed.

적용 대상

추가 정보