WebClient.DownloadFileCompleted Evento
Definizione
Importante
Alcune informazioni sono relative alla release non definitiva del prodotto, che potrebbe subire modifiche significative prima della release definitiva. Microsoft non riconosce alcuna garanzia, espressa o implicita, in merito alle informazioni qui fornite.
Si verifica al completamento di un'operazione asincrona di download di file.
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
Tipo evento
Esempio
Nell'esempio di codice seguente viene illustrata l'impostazione di un gestore eventi per l'evento 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
Commenti
Questo evento viene generato ogni volta che viene completata un'operazione di download di file asincrona. I download di file asincroni vengono avviati chiamando i DownloadFileAsync metodi .
AsyncCompletedEventHandler è il delegato per questo evento. La AsyncCompletedEventArgs classe fornisce al gestore eventi i dati dell'evento.
Per altre informazioni su come gestire gli eventi, vedere la gestione e generazione di eventi.
Si applica a
Commenti e suggerimenti
https://aka.ms/ContentUserFeedback.
Presto disponibile: Nel corso del 2024 verranno gradualmente disattivati i problemi di GitHub come meccanismo di feedback per il contenuto e ciò verrà sostituito con un nuovo sistema di feedback. Per altre informazioni, vedereInvia e visualizza il feedback per