WebClient.UploadProgressChanged WebClient.UploadProgressChanged WebClient.UploadProgressChanged WebClient.UploadProgressChanged Event

Definición

Se produce cuando una operación de carga asincrónica transfiere correctamente una parte o la totalidad de los datos.Occurs when an asynchronous upload operation successfully transfers some or all of the data.

public:
 event System::Net::UploadProgressChangedEventHandler ^ UploadProgressChanged;
public event System.Net.UploadProgressChangedEventHandler UploadProgressChanged;
member this.UploadProgressChanged : System.Net.UploadProgressChangedEventHandler 
Public Event UploadProgressChanged As UploadProgressChangedEventHandler 

Ejemplos

En el ejemplo de código siguiente se muestra cómo establecer un controlador de eventos para este evento.The following code example demonstrates setting an event handler for this event.

// Sample call: UploadFileInBackground2("http://www.contoso.com/fileUpload.aspx", "data.txt")
void UploadFileInBackground2( String^ address, String^ fileName )
{
   WebClient^ client = gcnew WebClient;
   Uri ^uri = gcnew Uri(address);

   client->UploadFileCompleted += 
     gcnew UploadFileCompletedEventHandler (UploadFileCallback2);
   
   // Specify a progress notification handler.
   client->UploadProgressChanged += 
       gcnew UploadProgressChangedEventHandler( UploadProgressCallback );
   client->UploadFileAsync( uri, "POST", fileName );
   Console::WriteLine( "File upload started." );
}


  // Sample call: UploadFileInBackground2("http://www.contoso.com/fileUpload.aspx", "data.txt")
  public static void UploadFileInBackground2 (string address, string fileName)
  {
      WebClient client = new WebClient ();
      Uri uri = new Uri(address);

      client.UploadFileCompleted += new UploadFileCompletedEventHandler (UploadFileCallback2);

// Specify a progress notification handler.
client.UploadProgressChanged += new UploadProgressChangedEventHandler(UploadProgressCallback);
      client.UploadFileAsync (uri, "POST", fileName);
      Console.WriteLine ("File upload started.");
  }

'  Sample call: UploadFileInBackground2("http:' www.contoso.com/fileUpload.aspx", "data.txt")
Public Shared Sub UploadFileInBackground2(ByVal address As String, ByVal fileName As String)

	Dim client As WebClient = New WebClient()
                      Dim uri as Uri =  New Uri(address)
	AddHandler client.UploadFileCompleted, AddressOf UploadFileCallback2

	'  Specify a progress notification handler.
	AddHandler client.UploadProgressChanged, AddressOf UploadProgressCallback
	client.UploadFileAsync(uri, "POST", fileName)
	Console.WriteLine("File upload started.")
End Sub

En el ejemplo de código siguiente se muestra una implementación de un controlador para este evento.The following code example shows an implementation of a handler for this event.

static void UploadProgressCallback(Object^ sender, 
          UploadProgressChangedEventArgs^ e)
      {
          // Displays the operation identifier, and the transfer progress.
          Console::WriteLine("{0}    uploaded {1} of {2} bytes. {3} % complete...", 
              (String ^)e->UserState, 
              e->BytesSent, 
              e->TotalBytesToSend,
              e->ProgressPercentage);
      }
static void DownloadProgressCallback(Object^ sender, 
          DownloadProgressChangedEventArgs^ e)
      {
          // Displays the operation identifier, and the transfer progress.
          Console::WriteLine("{0}    downloaded {1} of {2} bytes. {3} % complete...", 
              (String ^)e->UserState, 
              e->BytesReceived, 
              e->TotalBytesToReceive,
              e->ProgressPercentage);
      }
private static void UploadProgressCallback(object sender, UploadProgressChangedEventArgs e)
{
    // Displays the operation identifier, and the transfer progress.
    Console.WriteLine("{0}    uploaded {1} of {2} bytes. {3} % complete...", 
        (string)e.UserState, 
        e.BytesSent, 
        e.TotalBytesToSend,
        e.ProgressPercentage);
}
private static void DownloadProgressCallback(object sender, DownloadProgressChangedEventArgs e)
{
    // Displays the operation identifier, and the transfer progress.
    Console.WriteLine("{0}    downloaded {1} of {2} bytes. {3} % complete...", 
        (string)e.UserState, 
        e.BytesReceived, 
        e.TotalBytesToReceive,
        e.ProgressPercentage);
}
Private Shared Sub UploadProgressCallback(ByVal sender As Object, ByVal e As UploadProgressChangedEventArgs)

    '  Displays the operation identifier, and the transfer progress.
    Console.WriteLine("{0}    uploaded {1} of {2} bytes. {3} % complete...", _
     CStr(e.UserState), e.BytesSent, e.TotalBytesToSend, e.ProgressPercentage)
End Sub
Private Shared Sub DownloadProgressCallback(ByVal sender As Object, ByVal e As DownloadProgressChangedEventArgs)

    '  Displays the operation identifier, and the transfer progress.
    Console.WriteLine("0}    downloaded 1} of 2} bytes. 3} % complete...", _
     CStr(e.UserState), e.BytesReceived, e.TotalBytesToReceive, e.ProgressPercentage)
End Sub

Comentarios

Este evento se desencadena cada vez que se realiza una carga asincrónica.This event is raised each time an asynchronous upload makes progress. Este evento se desencadena cuando las cargas se inician mediante cualquiera de los métodos siguientes.This event is raised when uploads are started using any of the following methods.

MétodoMethod DescripciónDescription
UploadDataAsync Envía una Byte matriz al recurso, sin bloquear el subproceso que realiza la llamada.Sends a Byte array to the resource, without blocking the calling thread.
UploadFileAsync Envía un archivo local al recurso, sin bloquear el subproceso que realiza la llamada.Sends a local file to the resource, without blocking the calling thread.
UploadValuesAsync Envía un NameValueCollection al recurso y devuelve una Byte matriz que contiene cualquier respuesta, sin bloquear el subproceso que realiza la llamada.Sends a NameValueCollection to the resource and returns a Byte array containing any response, without blocking the calling thread.

UploadProgressChangedEventHandler Es el delegado de este evento.The UploadProgressChangedEventHandler is the delegate for this event. La UploadProgressChangedEventArgs clase proporciona el controlador de eventos con los datos de evento.The UploadProgressChangedEventArgs class provides the event handler with event data.

Para obtener más información acerca de cómo controlar eventos, vea controlar y provocar eventos.For more information about how to handle events, see Handling and Raising Events.

Se aplica a