NegotiateStream.EndRead(IAsyncResult) 메서드

정의

호출로 시작된 비동기 읽기 작업을 종료합니다 BeginRead(Byte[], Int32, Int32, AsyncCallback, Object).

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 에서 반환되는 인스턴스입니다 BeginRead(Byte[], Int32, Int32, AsyncCallback, Object).

반품

Int32 기본 스트림에서 읽은 바이트 수를 지정하는 값입니다.

예외

asyncResultnull입니다.

asyncResult가 호출에 BeginRead(Byte[], Int32, Int32, AsyncCallback, Object)의해 만들어지지 않았습니다.

완료할 보류 중인 읽기 작업이 없습니다.

-또는-

인증이 발생하지 않았습니다.

읽기 작업이 실패했습니다.

예제

다음 코드 예제에서는 비동기 읽기 작업을 종료하는 방법을 보여 줍니다. 작업을 시작하는 방법을 보여 주는 예제는 다음을 참조하세요 BeginRead.

private static void EndReadCallback(ClientState cState, int bytes)
{
    NegotiateStream authStream = (NegotiateStream)cState.AuthenticatedStream;
    // Read the client message.
    try
    {
        cState.Message.Append(Encoding.UTF8.GetChars(cState.Buffer, 0, bytes));
        if (bytes != 0)
        {
            Task<int> readTask = authStream.ReadAsync(cState.Buffer, 0, cState.Buffer.Length);
            readTask
                .ContinueWith(task => { EndReadCallback(cState, task.Result); })
                .Wait();

            return;
        }
    }
    catch (Exception e)
    {
        // A real application should do something
        // useful here, such as logging the failure.
        Console.WriteLine("Client message exception:");
        Console.WriteLine(e);
        return;
    }
    IIdentity id = authStream.RemoteIdentity;
    Console.WriteLine("{0} says {1}", id.Name, cState.Message.ToString());
}

설명

작업이 완료되지 않은 경우 이 메서드는 작업이 완료될 때까지 차단합니다.

이 작업을 동기적으로 수행하려면 메서드를 Read 사용합니다.

성공적으로 인증될 때까지 이 메서드를 호출할 수 없습니다. 인증하려면 , , AuthenticateAsClient, AuthenticateAsClientAsyncBeginAuthenticateAsClientAuthenticateAsServer또는 AuthenticateAsServerAsync 메서드 중 BeginAuthenticateAsServer하나를 호출합니다.

적용 대상