DownloadStringCompletedEventArgs Klasa

Definicja

Udostępnia dane dla zdarzenia DownloadStringCompleted.

public ref class DownloadStringCompletedEventArgs : System::ComponentModel::AsyncCompletedEventArgs
public class DownloadStringCompletedEventArgs : System.ComponentModel.AsyncCompletedEventArgs
type DownloadStringCompletedEventArgs = class
    inherit AsyncCompletedEventArgs
Public Class DownloadStringCompletedEventArgs
Inherits AsyncCompletedEventArgs
Dziedziczenie
DownloadStringCompletedEventArgs

Przykłady

Poniższy przykład kodu przedstawia asynchroniczne pobieranie ciągu.

// Sample call : DownloadStringInBackground2 ("http://www.contoso.com/GameScores.html");
void DownloadStringInBackground2( String^ address )
{
   WebClient^ client = gcnew WebClient;
   Uri ^uri = gcnew Uri(address);

   // Specify that the DownloadStringCallback2 method gets called
   // when the download completes.
   client->DownloadStringCompleted += gcnew DownloadStringCompletedEventHandler( DownloadStringCallback2 );
   client->DownloadStringAsync( uri );
}
// Sample call : DownloadStringInBackground2 ("http://www.contoso.com/GameScores.html");
public static void DownloadStringInBackground2(string address)
{
    WebClient client = new WebClient();
    Uri uri = new Uri(address);

    // Specify that the DownloadStringCallback2 method gets called
    // when the download completes.
    client.DownloadStringCompleted += new DownloadStringCompletedEventHandler(DownloadStringCallback2);
    client.DownloadStringAsync(uri);
}
'  Sample call : DownloadStringInBackground2 ("http:' www.contoso.com/GameScores.html")
Public Shared Sub DownloadStringInBackground2(ByVal address As String)

    Dim client As WebClient = New WebClient()

    '  Specify that the DownloadStringCallback2 method gets called
    '  when the download completes.
    AddHandler client.DownloadStringCompleted, AddressOf DownloadStringCallback2
                Dim uri as Uri = New Uri(address)
    client.DownloadStringAsync(uri)
End Sub

Następująca metoda jest wywoływana po zakończeniu pobierania.

void DownloadStringCallback2( Object^ /*sender*/, DownloadStringCompletedEventArgs^ e )
{

   // If the request was not canceled and did not throw
   // an exception, display the resource.
   if (  !e->Cancelled && e->Error == nullptr )
   {
      String^ textString = dynamic_cast<String^>(e->Result);
      Console::WriteLine( textString );
   }
}
private static void DownloadStringCallback2(Object sender, DownloadStringCompletedEventArgs e)
{
    // If the request was not canceled and did not throw
    // an exception, display the resource.
    if (!e.Cancelled && e.Error == null)
    {
        string textString = (string)e.Result;

        Console.WriteLine(textString);
    }
}
Private Shared Sub DownloadStringCallback2(ByVal sender As Object, ByVal e As DownloadStringCompletedEventArgs)

    '  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 textString As String = CStr(e.Result)
        Console.WriteLine(textString)
    End If
End Sub

Uwagi

Wystąpienia tej klasy są przekazywane do klasy DownloadStringCompletedEventHandler.

Właściwości

Cancelled

Pobiera wartość wskazującą, czy operacja asynchroniczna została anulowana.

(Odziedziczone po AsyncCompletedEventArgs)
Error

Pobiera wartość wskazującą, który błąd wystąpił podczas operacji asynchronicznej.

(Odziedziczone po AsyncCompletedEventArgs)
Result

Pobiera dane pobierane przez metodę DownloadStringAsync .

UserState

Pobiera unikatowy identyfikator zadania asynchronicznego.

(Odziedziczone po AsyncCompletedEventArgs)

Metody

Equals(Object)

Określa, czy dany obiekt jest taki sam, jak bieżący obiekt.

(Odziedziczone po Object)
GetHashCode()

Służy jako domyślna funkcja skrótu.

(Odziedziczone po Object)
GetType()

Type Pobiera wartość bieżącego wystąpienia.

(Odziedziczone po Object)
MemberwiseClone()

Tworzy płytkią kopię bieżącego Objectelementu .

(Odziedziczone po Object)
RaiseExceptionIfNecessary()

Zgłasza wyjątek dostarczony przez użytkownika, jeśli operacja asynchroniczna nie powiodła się.

(Odziedziczone po AsyncCompletedEventArgs)
ToString()

Zwraca ciąg reprezentujący bieżący obiekt.

(Odziedziczone po Object)

Dotyczy