WebClient.UploadStringCompleted Evento

Definición

Se produce cuando se completa una operación asincrónica de carga de cadenas.

public:
 event System::Net::UploadStringCompletedEventHandler ^ UploadStringCompleted;
public event System.Net.UploadStringCompletedEventHandler? UploadStringCompleted;
public event System.Net.UploadStringCompletedEventHandler UploadStringCompleted;
member this.UploadStringCompleted : System.Net.UploadStringCompletedEventHandler 
Public Custom Event UploadStringCompleted As UploadStringCompletedEventHandler 
Public Event UploadStringCompleted As UploadStringCompletedEventHandler 

Tipo de evento

Ejemplos

En el ejemplo de código siguiente se muestra cómo establecer un controlador de eventos para este evento.

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

En el ejemplo de código siguiente se muestra una implementación de un controlador para este evento.

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

Comentarios

Cautela

WebRequest, HttpWebRequest, ServicePointy WebClient están obsoletos y no debe usarlos para el nuevo desarrollo. Use HttpClient en su lugar.

Este evento se genera cada vez que se completa una operación de carga de cadenas asincrónicas. Las cargas de cadenas asincrónicas se inician llamando a los métodos de UploadStringAsync.

El UploadStringCompletedEventHandler es el delegado de este evento. La clase UploadStringCompletedEventArgs proporciona al controlador de eventos datos de eventos.

Para obtener más información sobre cómo controlar eventos, vea Control y generación de eventos.

Se aplica a