WebClient.DownloadFileCompleted Événement
Définition
Important
Certaines informations portent sur la préversion du produit qui est susceptible d’être en grande partie modifiée avant sa publication. Microsoft exclut toute garantie, expresse ou implicite, concernant les informations fournies ici.
Se produit lors d'une opération asynchrone de téléchargement de fichiers.
public:
event System::ComponentModel::AsyncCompletedEventHandler ^ DownloadFileCompleted;
public event System.ComponentModel.AsyncCompletedEventHandler? DownloadFileCompleted;
public event System.ComponentModel.AsyncCompletedEventHandler DownloadFileCompleted;
member this.DownloadFileCompleted : System.ComponentModel.AsyncCompletedEventHandler
Public Custom Event DownloadFileCompleted As AsyncCompletedEventHandler
Public Event DownloadFileCompleted As AsyncCompletedEventHandler
Type d'événement
Exemples
L’exemple de code suivant illustre la définition d’un gestionnaire d’événements pour l’événement DownloadFileCompleted
.
// Sample call : DownLoadFileInBackground2 ("http://www.contoso.com/logs/January.txt");
void DownLoadFileInBackground2( String^ address )
{
WebClient^ client = gcnew WebClient;
Uri ^uri = gcnew Uri(address);
// Call DownloadFileCallback2 when the download completes.
client->DownloadFileCompleted += gcnew AsyncCompletedEventHandler( DownloadFileCallback2 );
// Specify a progress notification handler here...
client->DownloadFileAsync( uri, "serverdata.txt" );
}
void DownloadFileCallback2( Object^ /*sender*/, System::ComponentModel::AsyncCompletedEventArgs^ e )
{
if ( e->Cancelled )
{
Console::WriteLine( "File download cancelled." );
}
if ( e->Error != nullptr )
{
Console::WriteLine( e->Error->ToString() );
}
}
// 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);
// Call DownloadFileCallback2 when the download completes.
client.DownloadFileCompleted += new AsyncCompletedEventHandler(DownloadFileCallback2);
// Specify a progress notification handler here ...
client.DownloadFileAsync(uri, "serverdata.txt");
}
private static void DownloadFileCallback2(object sender, AsyncCompletedEventArgs e)
{
if (e.Cancelled)
{
Console.WriteLine("File download cancelled.");
}
if (e.Error != null)
{
Console.WriteLine(e.Error.ToString());
}
}
' Sample call : DownLoadFileInBackground2 ("http:' www.contoso.com/logs/January.txt")
Public Shared Sub DownLoadFileInBackground2(address As String)
Dim client As WebClient = New WebClient()
' Call DownloadFileCallback2 when the download completes.
AddHandler client.DownloadFileCompleted, AddressOf DownloadFileCallback2
' Specify a progress notification handler here...
Dim uri as Uri = New Uri(address)
client.DownloadFileAsync(uri, "serverdata.txt")
End Sub
Private Shared Sub DownloadFileCallback2(sender As Object, e As AsyncCompletedEventArgs)
If e.Cancelled = True Then
Console.WriteLine("File download cancelled.")
End If
If Not e.Error Is Nothing Then
Console.WriteLine(e.Error.ToString())
End If
End Sub
Remarques
Cet événement est déclenché chaque fois qu’une opération de téléchargement de fichier asynchrone se termine. Les téléchargements de fichiers asynchrones sont démarrés en appelant les DownloadFileAsync méthodes.
AsyncCompletedEventHandler est le délégué de cet événement. La AsyncCompletedEventArgs classe fournit au gestionnaire d’événements des données d’événement.
Pour plus d’informations sur la façon de gérer les événements, consultez gestion et déclenchement d’événements.
S’applique à
Commentaires
https://aka.ms/ContentUserFeedback.
Bientôt disponible : Tout au long de l’année 2024, nous abandonnerons progressivement le mécanisme de retour d’information GitHub Issues pour le remplacer par un nouveau système de commentaires. Pour plus d’informations, consultez :Soumettre et afficher des commentaires pour