다음을 통해 공유


FtpWebRequest.EndGetRequestStream(IAsyncResult) 메서드

정의

로 시작된 BeginGetRequestStream(AsyncCallback, Object)보류 중인 비동기 작업을 종료합니다.

public:
 override System::IO::Stream ^ EndGetRequestStream(IAsyncResult ^ asyncResult);
public override System.IO.Stream EndGetRequestStream(IAsyncResult asyncResult);
override this.EndGetRequestStream : IAsyncResult -> System.IO.Stream
Public Overrides Function EndGetRequestStream (asyncResult As IAsyncResult) As Stream

매개 변수

asyncResult
IAsyncResult

IAsyncResult 작업이 시작될 때 반환된 개체입니다.

반환

이 인스턴스와 연결된 쓰기 가능한 Stream 인스턴스입니다.

예외

asyncResultnull입니다.

asyncResult 를 호출 BeginGetRequestStream(AsyncCallback, Object)하여 가져오지 못했습니다.

로 식별된 작업에 대해 이 메서드가 이미 호출되었습니다 asyncResult.

예제

다음 코드 예제에서는 요청의 스트림을 가져오기 위해 비동기 작업을 종료하는 방법을 보여 줍니다. 이 코드 예제는 클래스 개요에 제공된 더 큰 예제의 FtpWebRequest 일부입니다.

private static void EndGetStreamCallback(IAsyncResult ar)
{
    FtpState state = (FtpState) ar.AsyncState;

    Stream requestStream = null;
    // End the asynchronous call to get the request stream.
    try
    {
        requestStream = state.Request.EndGetRequestStream(ar);
        // Copy the file contents to the request stream.
        const int bufferLength = 2048;
        byte[] buffer = new byte[bufferLength];
        int count = 0;
        int readBytes = 0;
        FileStream stream = File.OpenRead(state.FileName);
        do
        {
            readBytes = stream.Read(buffer, 0, bufferLength);
            requestStream.Write(buffer, 0, readBytes);
            count += readBytes;
        }
        while (readBytes != 0);
        Console.WriteLine ("Writing {0} bytes to the stream.", count);
        // IMPORTANT: Close the request stream before sending the request.
        requestStream.Close();
        // Asynchronously get the response to the upload request.
        state.Request.BeginGetResponse(
            new AsyncCallback (EndGetResponseCallback),
            state
        );
    }
    // Return exceptions to the main application thread.
    catch (Exception e)
    {
        Console.WriteLine("Could not get the request stream.");
        state.OperationException = e;
        state.OperationComplete.Set();
        return;
    }
}

설명

작업이 완료되지 않은 경우 메서드는 EndGetRequestStream 작업이 완료될 때까지 차단합니다. 작업이 완료되었는지 확인하려면 호출EndGetRequestStream하기 전에 속성을 확인 IsCompleted 합니다.

"예외" EndGetRequestStream 에 명시된 예외 외에도 쓰기 위해 스트림을 여는 동안 throw된 예외를 다시 throw합니다.

메모

이 멤버는 애플리케이션에서 네트워크 추적을 사용하도록 설정할 때 추적 정보를 출력합니다. 자세한 내용은 .NET Framework의 네트워크 추적을 참조하세요.

적용 대상

추가 정보