DownloadDataCompletedEventArgs DownloadDataCompletedEventArgs DownloadDataCompletedEventArgs DownloadDataCompletedEventArgs Class

Definition

Stellt Daten für das DownloadDataCompleted-Ereignis bereit.Provides data for the DownloadDataCompleted event.

public ref class DownloadDataCompletedEventArgs : System::ComponentModel::AsyncCompletedEventArgs
public class DownloadDataCompletedEventArgs : System.ComponentModel.AsyncCompletedEventArgs
type DownloadDataCompletedEventArgs = class
    inherit AsyncCompletedEventArgs
Public Class DownloadDataCompletedEventArgs
Inherits AsyncCompletedEventArgs
Vererbung
DownloadDataCompletedEventArgsDownloadDataCompletedEventArgsDownloadDataCompletedEventArgsDownloadDataCompletedEventArgs

Beispiele

Im folgenden Codebeispiel wird das Herunterladen einer benutzerdefinierten Ressource veranschaulicht.The following code example demonstrates downloading a user-specified resource.

// Sample call : DownLoadDataInBackground ("http://www.contoso.com/GameScores.html");
void DownloadDataInBackground( String^ address )
{
   System::Threading::AutoResetEvent^ waiter = gcnew System::Threading::AutoResetEvent( false );
   WebClient^ client = gcnew WebClient;
   Uri ^uri = gcnew Uri(address);
   
   // Specify that the DownloadDataCallback method gets called
   // when the download completes.
   client->DownloadDataCompleted += gcnew 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 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

Die folgende Methode wird aufgerufen, wenn der Download abgeschlossen ist.The following method is called when the download completes.

void DownloadDataCallback( Object^ /*sender*/, DownloadDataCompletedEventArgs^ e )
{
   System::Threading::AutoResetEvent^ waiter = dynamic_cast<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 == nullptr )
      {
         array<Byte>^data = dynamic_cast<array<Byte>^>(e->Result);
         String^ textData = System::Text::Encoding::UTF8->GetString( data );
         Console::WriteLine( textData );
      }
   }
   finally
   {
      
      // Let the main application thread resume.
      waiter->Set();
   }

}


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

Hinweise

Instanzen dieser Klasse werden an die DownloadDataCompletedEventHandler-Klasse übermittelt.Instances of this class are passed to the DownloadDataCompletedEventHandler.

Eigenschaften

Cancelled Cancelled Cancelled Cancelled

Ruft einen Wert ab, der angibt, ob ein asynchroner Vorgang abgebrochen wurde.Gets a value indicating whether an asynchronous operation has been canceled.

(Inherited from AsyncCompletedEventArgs)
Error Error Error Error

Ruft einen Wert ab, der angibt, welcher Fehler während eines asynchronen Vorgangs aufgetreten ist.Gets a value indicating which error occurred during an asynchronous operation.

(Inherited from AsyncCompletedEventArgs)
Result Result Result Result

Ruft die von einer DownloadDataAsync-Methode heruntergeladenen Daten ab.Gets the data that is downloaded by a DownloadDataAsync method.

UserState UserState UserState UserState

Ruft den eindeutigen Bezeichner der asynchronen Aufgabe ab.Gets the unique identifier for the asynchronous task.

(Inherited from AsyncCompletedEventArgs)

Methoden

Equals(Object) Equals(Object) Equals(Object) Equals(Object)

Bestimmt, ob das angegebene Objekt mit dem aktuellen Objekt identisch ist.Determines whether the specified object is equal to the current object.

(Inherited from Object)
GetHashCode() GetHashCode() GetHashCode() GetHashCode()

Fungiert als Standardhashfunktion.Serves as the default hash function.

(Inherited from Object)
GetType() GetType() GetType() GetType()

Ruft den Type der aktuellen Instanz ab.Gets the Type of the current instance.

(Inherited from Object)
MemberwiseClone() MemberwiseClone() MemberwiseClone() MemberwiseClone()

Erstellt eine flache Kopie des aktuellen Object.Creates a shallow copy of the current Object.

(Inherited from Object)
RaiseExceptionIfNecessary() RaiseExceptionIfNecessary() RaiseExceptionIfNecessary() RaiseExceptionIfNecessary()

Löst eine benutzerdefinierte Ausnahme aus, wenn bei einem asynchronen Vorgang ein Fehler aufgetreten ist.Raises a user-supplied exception if an asynchronous operation failed.

(Inherited from AsyncCompletedEventArgs)
ToString() ToString() ToString() ToString()

Gibt eine Zeichenfolge zurück, die das aktuelle Objekt darstellt.Returns a string that represents the current object.

(Inherited from Object)

Gilt für: