UploadDataCompletedEventHandler Delegar
Definição
Representa o método que manipulará o evento de UploadDataCompleted de WebClient.Represents the method that will handle the UploadDataCompleted event of a WebClient.
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)
Parâmetros
- sender
- Object
A fonte do evento.The source of the event.
Um UploadDataCompletedEventArgs que contém dados de evento.A UploadDataCompletedEventArgs containing event data.
Exemplos
O exemplo de código a seguir demonstra o carregamento de dados de forma assíncrona.The following code example demonstrates asynchronously uploading data.
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
O método a seguir é chamado quando o carregamento é concluído.The following method is called when the upload completes.
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
Comentários
Ao criar um UploadDataCompletedEventHandler delegado, você identifica o método que manipulará o evento.When you create a UploadDataCompletedEventHandler delegate, you identify the method that will handle the event. Para associar o evento ao manipulador de eventos, adicione uma instância do delegado ao evento.To associate the event with your event handler, add an instance of the delegate to the event. O manipulador de eventos é chamado sempre que o evento ocorre, a menos que você remova o representante.The event handler is called whenever the event occurs, unless you remove the delegate. Para obter mais informações sobre delegados de manipulador de eventos, consulte manipulando e gerando eventos.For more information about event handler delegates, see Handling and Raising Events.
Métodos de Extensão
GetMethodInfo(Delegate) |
Obtém um objeto que representa o método representado pelo delegado especificado.Gets an object that represents the method represented by the specified delegate. |