DownloadProgressChangedEventHandler DownloadProgressChangedEventHandler DownloadProgressChangedEventHandler DownloadProgressChangedEventHandler Delegate

Definizione

Rappresenta il metodo che gestirà l'evento DownloadProgressChanged di un oggetto WebClient.Represents the method that will handle the DownloadProgressChanged event of a WebClient.

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

Parametri

sender
Object Object Object Object

Origine dell'evento.The source of the event.

Ereditarietà
DownloadProgressChangedEventHandlerDownloadProgressChangedEventHandlerDownloadProgressChangedEventHandlerDownloadProgressChangedEventHandler

Esempi

Nell'esempio di codice riportato di seguito viene illustrata l' WebClient.DownloadProgressChanged impostazione di un gestore eventi per l'evento.The following code example demonstrates setting an event handler for the WebClient.DownloadProgressChanged event.

// Sample call : DownLoadFileInBackground2 ("http://www.contoso.com/logs/January.txt");
void DownLoadFileInBackground2( String^ address )
{
   WebClient^ client = gcnew WebClient;
   Uri ^uri = gcnew Uri(address);
   
   // Specify that the DownloadFileCallback method gets called
   // when the download completes.
   client->DownloadFileCompleted += gcnew AsyncCompletedEventHandler( DownloadFileCallback2 );
   
   // Specify a progress notification handler.
   client->DownloadProgressChanged += gcnew DownloadProgressChangedEventHandler( DownloadProgressCallback );
   client->DownloadFileAsync( uri, "serverdata.txt" );
}


// Sample call : DownLoadFileInBackground2 ("http://www.contoso.com/logs/January.txt");
public static void DownLoadFileInBackground2 (string address)
{
    WebClient client = new WebClient ();
    Uri uri = new Uri(address);

    // Specify that the DownloadFileCallback method gets called
    // when the download completes.
    client.DownloadFileCompleted += new AsyncCompletedEventHandler (DownloadFileCallback2);
    // Specify a progress notification handler.
    client.DownloadProgressChanged += new DownloadProgressChangedEventHandler(DownloadProgressCallback);
    client.DownloadFileAsync (uri, "serverdata.txt");
}

'  Sample call : DownLoadFileInBackground2 ("http:' www.contoso.com/logs/January.txt")
Public Shared Sub DownLoadFileInBackground2(ByVal address As String)

	Dim client As WebClient = New WebClient()

	'  Specify that the DownloadFileCallback method gets called
	'  when the download completes.
	AddHandler client.DownloadFileCompleted, AddressOf DownloadFileCallback2
	'  Specify a progress notification handler.
	AddHandler client.DownloadProgressChanged, AddressOf DownloadProgressCallback
                      Dim uri as Uri = New Uri(address)
	client.DownloadFileAsync(uri, "serverdata.txt")
End Sub

Commenti

Quando si crea un delegato DownloadProgressChangedEventHandler, si identifica il metodo che gestirà l'evento.When you create a DownloadProgressChangedEventHandler delegate, you identify the method that will handle the event. Per associare l'evento al gestore eventi in uso, aggiungere all'evento un'istanza del delegato.To associate the event with your event handler, add an instance of the delegate to the event. Il gestore eventi viene chiamato ogni volta che si verifica l'evento, a meno che non venga rimosso il delegato.The event handler is called whenever the event occurs, unless you remove the delegate. Per ulteriori informazioni sui delegati del gestore eventi, vedere gestione e generazione di eventi.For more information about event handler delegates, see Handling and Raising Events. Gestione e generazione di eventiHandling and Raising Events

Nota

Se il server non invia le dimensioni del file scaricato, ad esempio nel caso di una connessione FTP passiva, ProgressPercentage può essere sempre zero.If the server does not send the size of the downloaded file (such as in the case of a passive FTP connection), ProgressPercentage may always be zero.

Metodi di estensione

GetMethodInfo(Delegate) GetMethodInfo(Delegate) GetMethodInfo(Delegate) GetMethodInfo(Delegate)

Ottiene un oggetto che rappresenta il metodo rappresentato dal delegato specificato.Gets an object that represents the method represented by the specified delegate.

Si applica a