UploadDataCompletedEventHandler 대리자

정의

UploadDataCompletedWebClient 이벤트를 처리할 메서드를 나타냅니다.

public delegate void UploadDataCompletedEventHandler(System::Object ^ sender, UploadDataCompletedEventArgs ^ e);
public delegate void UploadDataCompletedEventHandler(object sender, UploadDataCompletedEventArgs e);
type UploadDataCompletedEventHandler = delegate of obj * UploadDataCompletedEventArgs -> unit
Public Delegate Sub UploadDataCompletedEventHandler(sender As Object, e As UploadDataCompletedEventArgs)

매개 변수

sender
Object

이벤트 소스입니다.

e
UploadDataCompletedEventArgs

이벤트 데이터가 포함된 UploadDataCompletedEventArgs입니다.

예제

다음 코드 예제에서는 데이터를 비동기적으로 업로드하는 방법을 보여 줍니다.

void UploadDataInBackground2( String^ address )
{
   WebClient^ client = gcnew WebClient;
   Uri ^uri = gcnew Uri(address);
   String^ text = "Time = 12:00am temperature = 50";
   array<Byte>^data = System::Text::Encoding::UTF8->GetBytes( text );
   String^ method = "POST";

   client->UploadDataCompleted += gcnew UploadDataCompletedEventHandler( UploadDataCallback2 );
   client->UploadDataAsync( uri, method, data );
}
public static void UploadDataInBackground2(string address)
{
    WebClient client = new WebClient();
    Uri uri = new Uri(address);
    string text = "Time = 12:00am temperature = 50";
    byte[] data = System.Text.Encoding.UTF8.GetBytes(text);
    string method = "POST";

    client.UploadDataCompleted += new UploadDataCompletedEventHandler(UploadDataCallback2);
    client.UploadDataAsync(uri, method, data);
}
Public Shared Sub UploadDataInBackground2(ByVal address As String)

    Dim client As WebClient = New WebClient()
    Dim text As String = "Time = 12:00am temperature = 50"
    Dim data() As Byte = System.Text.Encoding.UTF8.GetBytes(text)
    Dim method As String = "POST"

    AddHandler client.UploadDataCompleted, AddressOf UploadDataCallback2
    Dim uri as Uri = New Uri(address)
                client.UploadDataAsync(uri, method, data)
End Sub

다음 메서드는 업로드가 완료 되 면 호출 됩니다.

void UploadDataCallback2( Object^ /*sender*/, UploadDataCompletedEventArgs^ e )
{
   array<Byte>^data = dynamic_cast<array<Byte>^>(e->Result);
   String^ reply = System::Text::Encoding::UTF8->GetString( data );
   Console::WriteLine( reply );
}
private static void UploadDataCallback2(Object sender, UploadDataCompletedEventArgs e)
{
    byte[] data = (byte[])e.Result;
    string reply = System.Text.Encoding.UTF8.GetString(data);

    Console.WriteLine(reply);
}
Private Shared Sub UploadDataCallback2(ByVal sender As Object, ByVal e As UploadDataCompletedEventArgs)

    Dim data() As Byte = CType(e.Result, Byte())
    Dim reply As String = System.Text.Encoding.UTF8.GetString(data)

    Console.WriteLine(reply)
End Sub

설명

UploadDataCompletedEventHandler 대리자를 만들 때, 이벤트를 처리할 메서드를 식별합니다. 이벤트를 이벤트 처리기와 연결하려면 대리자의 인스턴스를 해당 이벤트에 추가합니다. 대리자를 제거하지 않는 경우 이벤트가 발생할 때마다 이벤트 처리기가 호출됩니다. 이벤트 처리기 대리자에 대 한 자세한 내용은 참조 하세요. 이벤트 처리 및 발생합니다.

확장 메서드

GetMethodInfo(Delegate)

지정된 대리자가 나타내는 메서드를 나타내는 개체를 가져옵니다.

적용 대상