Compartilhar via


UploadStringCompletedEventHandler Delegar

Definição

Representa o método que manipulará o evento de UploadStringCompleted de WebClient.

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

Parâmetros

sender
Object

A fonte do evento.

Exemplos

O exemplo de código a seguir demonstra o carregamento assíncrono de uma cadeia de caracteres.

void UploadStringInBackground2( String^ address )
{
   WebClient^ client = gcnew WebClient;
   Uri ^uri = gcnew Uri(address);
   String^ data = "Time = 12:00am temperature = 50";

   client->UploadStringCompleted += gcnew UploadStringCompletedEventHandler( UploadStringCallback2 );
   client->UploadStringAsync( uri, data );
}
public static void UploadStringInBackground2(string address)
{
    WebClient client = new WebClient();
    Uri uri = new Uri(address);
    string data = "Time = 12:00am temperature = 50";
    client.UploadStringCompleted += new UploadStringCompletedEventHandler(UploadStringCallback2);
    client.UploadStringAsync(uri, data);
}
Public Shared Sub UploadStringInBackground2(ByVal address As String)

    Dim client As WebClient = New WebClient()
    Dim data As String = "Time = 12:00am temperature = 50"
    AddHandler client.UploadStringCompleted, AddressOf UploadStringCallback2
                Dim uri as Uri = New Uri(address)
    client.UploadStringAsync(uri, data)
End Sub

O método a seguir é chamado quando o upload é concluído.

void UploadStringCallback2( Object^ /*sender*/, UploadStringCompletedEventArgs^ e )
{
   String^ reply = dynamic_cast<String^>(e->Result);
   Console::WriteLine( reply );
}
private static void UploadStringCallback2(Object sender, UploadStringCompletedEventArgs e)
{
    string reply = (string)e.Result;
    Console.WriteLine(reply);
}
Private Shared Sub UploadStringCallback2(ByVal sender As Object, ByVal e As UploadStringCompletedEventArgs)
    Dim reply As String = CStr(e.Result)
    Console.WriteLine(reply)
End Sub

Comentários

Ao criar um UploadStringCompletedEventHandler delegado, você identifica o método que manipulará o evento. Para associar o evento ao manipulador de eventos, adicione uma instância do delegado ao evento. O manipulador de eventos é chamado sempre que o evento ocorre, a menos que você remova o representante. Para obter mais informações sobre representantes do manipulador de eventos, consulte Manipulando e gerando eventos.

Métodos de Extensão

GetMethodInfo(Delegate)

Obtém um objeto que representa o método representado pelo delegado especificado.

Aplica-se a