WebClient.OpenWriteCompleted 이벤트

정의

리소스에 데이터를 쓸 스트림을 여는 비동기 작업이 완료되면 발생합니다.

public:
 event System::Net::OpenWriteCompletedEventHandler ^ OpenWriteCompleted;
public event System.Net.OpenWriteCompletedEventHandler? OpenWriteCompleted;
public event System.Net.OpenWriteCompletedEventHandler OpenWriteCompleted;
member this.OpenWriteCompleted : System.Net.OpenWriteCompletedEventHandler 
Public Custom Event OpenWriteCompleted As OpenWriteCompletedEventHandler 
Public Event OpenWriteCompleted As OpenWriteCompletedEventHandler 

이벤트 유형

예제

다음 코드 예제에서는이 이벤트에 대 한 이벤트 처리기를 설정 하는 방법을 보여 줍니다.

void OpenResourceForWriting2( String^ address )
{
   WebClient^ client = gcnew WebClient;
   Uri ^uri = gcnew Uri(address);

   // Specify that the OpenWriteCallback method gets called
   // when the writeable stream is available.
   client->OpenWriteCompleted += gcnew OpenWriteCompletedEventHandler( OpenWriteCallback2 );
   client->OpenWriteAsync( uri, "POST" );

   // Applications can perform other tasks
   // while waiting for the upload to complete.
}
public static void OpenResourceForWriting2(string address)
{
    WebClient client = new WebClient();
    Uri uri = new Uri(address);

    // Specify that the OpenWriteCallback method gets called
    // when the writeable stream is available.
    client.OpenWriteCompleted += new OpenWriteCompletedEventHandler(OpenWriteCallback2);
    client.OpenWriteAsync(uri, "POST");
    // Applications can perform other tasks
    // while waiting for the upload to complete.
}
Public Shared Sub OpenResourceForWriting2(ByVal address As String)

    Dim client As WebClient = New WebClient()

    '  Specify that the OpenWriteCallback method gets called
    '  when the writeable stream is available.
    AddHandler client.OpenWriteCompleted, AddressOf OpenWriteCallback2
                Dim uri as Uri = New Uri(address)
    client.OpenWriteAsync(uri, "POST")
    '  Applications can perform other tasks
    '  while waiting for the upload to complete.
End Sub

다음 코드 예제에서는이 이벤트에 대 한 처리기의 구현을 보여 입니다.

void OpenWriteCallback2( Object^ /*sender*/, OpenWriteCompletedEventArgs^ e )
{
   Stream^ body = nullptr;
   StreamWriter^ s = nullptr;
   try
   {
      body = dynamic_cast<Stream^>(e->Result);
      s = gcnew StreamWriter( body );
      s->AutoFlush = true;
      s->Write( "This is content data to be sent to the server." );
   }
   finally
   {
      if ( s != nullptr )
      {
         s->Close();
      }
      if ( body != nullptr )
      {
         body->Close();
      }
   }

}
private static void OpenWriteCallback2(Object sender, OpenWriteCompletedEventArgs e)
{
    Stream body = null;
    StreamWriter s = null;

    try
    {
        body = (Stream)e.Result;
        s = new StreamWriter(body);
        s.AutoFlush = true;
        s.Write("This is content data to be sent to the server.");
    }
    finally
    {
        if (s != null)
        {
            s.Close();
        }

        if (body != null)
        {
            body.Close();
        }
    }
}
Private Shared Sub OpenWriteCallback2(ByVal sender As Object, ByVal e As OpenWriteCompletedEventArgs)

    Dim body As Stream = Nothing
    Dim s As StreamWriter = Nothing

    Try

        body = CType(e.Result, Stream)
        s = New StreamWriter(body)
        s.AutoFlush = True
        s.Write("This is content data to be sent to the server.")
    Finally

        If Not s Is Nothing Then

            s.Close()
        End If

        If Not body Is Nothing Then

            body.Close()
        End If
    End Try
End Sub

설명

이 이벤트는 리소스에 데이터를 보내는 데 사용되는 스트림을 열기 위한 비동기 작업이 완료될 때마다 발생합니다. 이러한 작업은 메서드를 호출하여 시작됩니다 OpenWriteAsync .

OpenWriteCompletedEventHandler 이 이벤트의 대리자입니다. 클래스는 OpenWriteCompletedEventArgs 이벤트 데이터와 함께 이벤트 처리기를 제공합니다.

이벤트를 처리 하는 방법에 대 한 자세한 내용은 참조 하세요. 이벤트 처리 및 발생합니다.

적용 대상