DownloadDataCompletedEventArgs Klasa
Definicja
Ważny
Niektóre informacje dotyczą produktów przedpremierowych, które mogą zostać znacznie zmodyfikowane przed premierą. Microsoft nie udziela żadnych gwarancji, ani wyraźnych, ani domniemanych, dotyczących informacji podanych tutaj.
Udostępnia dane dla zdarzenia DownloadDataCompleted.
public ref class DownloadDataCompletedEventArgs : System::ComponentModel::AsyncCompletedEventArgs
public class DownloadDataCompletedEventArgs : System.ComponentModel.AsyncCompletedEventArgs
type DownloadDataCompletedEventArgs = class
inherit AsyncCompletedEventArgs
Public Class DownloadDataCompletedEventArgs
Inherits AsyncCompletedEventArgs
- Dziedziczenie
Przykłady
Poniższy przykład kodu przedstawia pobieranie zasobu określonego przez użytkownika.
// Sample call : DownLoadDataInBackground ("http://www.contoso.com/GameScores.html");
public static void DownloadDataInBackground(string address)
{
System.Threading.AutoResetEvent waiter = new System.Threading.AutoResetEvent(false);
WebClient client = new WebClient();
Uri uri = new Uri(address);
// Specify that the DownloadDataCallback method gets called
// when the download completes.
client.DownloadDataCompleted += new DownloadDataCompletedEventHandler(DownloadDataCallback);
client.DownloadDataAsync(uri, waiter);
// Block the main application thread. Real applications
// can perform other tasks while waiting for the download to complete.
waiter.WaitOne();
}
' Sample call : DownLoadDataInBackground ("http:' www.contoso.com/GameScores.html")
Public Shared Sub DownloadDataInBackground(ByVal address As String)
Dim waiter As System.Threading.AutoResetEvent = New System.Threading.AutoResetEvent(False)
Dim client As WebClient = New WebClient()
' Specify that the DownloadDataCallback method gets called
' when the download completes.
AddHandler client.DownloadDataCompleted, AddressOf DownloadDataCallback
Dim uri as Uri = New Uri(address)
client.DownloadDataAsync(uri, waiter)
' Block the main application thread. Real applications
' can perform other tasks while waiting for the download to complete.
waiter.WaitOne()
End Sub
Następująca metoda jest wywoływana po zakończeniu pobierania.
private static void DownloadDataCallback(Object sender, DownloadDataCompletedEventArgs e)
{
System.Threading.AutoResetEvent waiter = (System.Threading.AutoResetEvent)e.UserState;
try
{
// If the request was not canceled and did not throw
// an exception, display the resource.
if (!e.Cancelled && e.Error == null)
{
byte[] data = (byte[])e.Result;
string textData = System.Text.Encoding.UTF8.GetString(data);
Console.WriteLine(textData);
}
}
finally
{
// Let the main application thread resume.
waiter.Set();
}
}
Private Shared Sub DownloadDataCallback(ByVal sender As Object, ByVal e As DownloadDataCompletedEventArgs)
Dim waiter As System.Threading.AutoResetEvent = CType(e.UserState, System.Threading.AutoResetEvent)
Try
' If the request was not canceled and did not throw
' an exception, display the resource.
If e.Cancelled = False AndAlso e.Error Is Nothing Then
Dim data() As Byte = CType(e.Result, Byte())
Dim textData As String = System.Text.Encoding.UTF8.GetString(data)
Console.WriteLine(textData)
End If
Finally
' Let the main application thread resume.
waiter.Set()
End Try
End Sub
Uwagi
Wystąpienia tej klasy są przekazywane do klasy DownloadDataCompletedEventHandler.
Właściwości
| Nazwa | Opis |
|---|---|
| Cancelled |
Pobiera wartość wskazującą, czy operacja asynchroniczna została anulowana. (Dziedziczone od AsyncCompletedEventArgs) |
| Error |
Pobiera wartość wskazującą, który błąd wystąpił podczas operacji asynchronicznej. (Dziedziczone od AsyncCompletedEventArgs) |
| Result |
Pobiera dane pobierane przez metodę DownloadDataAsync . |
| UserState |
Pobiera unikatowy identyfikator zadania asynchronicznego. (Dziedziczone od AsyncCompletedEventArgs) |
Metody
| Nazwa | Opis |
|---|---|
| Equals(Object) |
Określa, czy dany obiekt jest taki sam, jak bieżący obiekt. (Dziedziczone od Object) |
| GetHashCode() |
Służy jako domyślna funkcja skrótu. (Dziedziczone od Object) |
| GetType() |
Type Pobiera bieżące wystąpienie. (Dziedziczone od Object) |
| MemberwiseClone() |
Tworzy płytkią kopię bieżącego Objectelementu . (Dziedziczone od Object) |
| RaiseExceptionIfNecessary() |
Zgłasza wyjątek dostarczony przez użytkownika, jeśli operacja asynchroniczna nie powiodła się. (Dziedziczone od AsyncCompletedEventArgs) |
| ToString() |
Zwraca ciąg reprezentujący bieżący obiekt. (Dziedziczone od Object) |