WebClient.UploadDataCompleted Evento
Definición
Importante
Parte de la información hace referencia a la versión preliminar del producto, que puede haberse modificado sustancialmente antes de lanzar la versión definitiva. Microsoft no otorga ninguna garantía, explícita o implícita, con respecto a la información proporcionada aquí.
Se produce cuando se completa una operación asincrónica de carga de datos.
public:
event System::Net::UploadDataCompletedEventHandler ^ UploadDataCompleted;
public event System.Net.UploadDataCompletedEventHandler? UploadDataCompleted;
public event System.Net.UploadDataCompletedEventHandler UploadDataCompleted;
member this.UploadDataCompleted : System.Net.UploadDataCompletedEventHandler
Public Custom Event UploadDataCompleted As UploadDataCompletedEventHandler
Public Event UploadDataCompleted As UploadDataCompletedEventHandler
Tipo de evento
Ejemplos
En el ejemplo de código siguiente se muestra cómo establecer un controlador de eventos para este evento.
void UploadDataInBackground3( 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 );
client->UploadDataCompleted += gcnew UploadDataCompletedEventHandler( UploadDataCallback3 );
client->UploadDataAsync( uri, data );
}
public static void UploadDataInBackground3(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);
client.UploadDataCompleted += new UploadDataCompletedEventHandler(UploadDataCallback3);
client.UploadDataAsync(uri, data);
}
Public Shared Sub UploadDataInBackground3(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)
AddHandler client.UploadDataCompleted, AddressOf UploadDataCallback3
Dim uri as Uri = New Uri(address)
client.UploadDataAsync(uri, data)
End Sub
En el ejemplo de código siguiente se muestra una implementación de un controlador para este evento.
void UploadDataCallback3( 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 UploadDataCallback3(Object sender, UploadDataCompletedEventArgs e)
{
byte[] data = (byte[])e.Result;
string reply = System.Text.Encoding.UTF8.GetString(data);
Console.WriteLine(reply);
}
Private Shared Sub UploadDataCallback3(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
Comentarios
Cautela
WebRequest
, HttpWebRequest
, ServicePoint
y 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 datos asincrónica. Las cargas de datos asincrónicas se inician llamando a los métodos UploadDataAsync.
El UploadDataCompletedEventHandler es el delegado de este evento. La clase UploadDataCompletedEventArgs 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.