FtpWebRequest.EndGetRequestStream(IAsyncResult) Yöntem

Tanım

ile BeginGetRequestStream(AsyncCallback, Object)başlatılan bekleyen zaman uyumsuz işlemi sonlandırır.

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

Parametreler

asyncResult
IAsyncResult

IAsyncResult İşlem başlatıldığında döndürülen nesne.

Döndürülenler

Bu örnekle ilişkilendirilmiş yazılabilir Stream bir örnek.

Özel durumlar

asyncResult, null değeridir.

asyncResult çağrılarak BeginGetRequestStream(AsyncCallback, Object)elde edilemedi.

Bu yöntem tarafından asyncResulttanımlanan işlem için zaten çağrıldı.

Örnekler

Aşağıdaki kod örneği, isteğin akışını almak için zaman uyumsuz bir işlemi sonlandırmayı gösterir. Bu kod örneği, sınıfa genel bakış için FtpWebRequest sağlanan daha büyük bir örneğin bir parçasıdır.

private:
   static void EndGetStreamCallback( IAsyncResult^ ar )
   {
      FtpState^ state = dynamic_cast<FtpState^>(ar->AsyncState);
      Stream^ requestStream = nullptr;

      // 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;
         array<Byte>^buffer = gcnew array<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, bufferLength );
            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( gcnew 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;
      }
   }
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;
    }
}

Açıklamalar

İşlem tamamlanmadıysa, EndGetRequestStream yöntem işlem tamamlanana kadar engeller. İşlemin tamamlanıp tamamlanmadığını belirlemek için çağrısı EndGetRequestStreamyapmadan IsCompleted önce özelliğini denetleyin.

"Özel durumlar" EndGetRequestStream içinde belirtilen özel durumlara ek olarak, akışı yazmak üzere açarken oluşan özel durumları yeniden oluşturur.

Not

Uygulamanızda ağ izlemeyi etkinleştirdiğinizde, bu üye izleme bilgilerini çıkarır. Daha fazla bilgi için .NET Framework ağ izleme bölümüne bakın.

Şunlara uygulanır

Ayrıca bkz.