DownloadDataCompletedEventArgs Clase

Definición

Proporciona datos para el evento DownloadDataCompleted.

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

Ejemplos

En el ejemplo de código siguiente se muestra cómo descargar un recurso especificado por el usuario.

// 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

Se llama al método siguiente cuando se completa la descarga.

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

Comentarios

Las instancias de esta clase se pasan a DownloadDataCompletedEventHandler.

Propiedades

Cancelled

Obtiene un valor que indica si se ha cancelado una operación asincrónica.

(Heredado de AsyncCompletedEventArgs)
Error

Obtiene un valor que indica el error que se produjo durante una operación asincrónica.

(Heredado de AsyncCompletedEventArgs)
Result

Obtiene los datos descargados por un método DownloadDataAsync.

UserState

Obtiene el identificador único de la tarea asincrónica.

(Heredado de AsyncCompletedEventArgs)

Métodos

Equals(Object)

Determina si el objeto especificado es igual que el objeto actual.

(Heredado de Object)
GetHashCode()

Sirve como la función hash predeterminada.

(Heredado de Object)
GetType()

Obtiene el Type de la instancia actual.

(Heredado de Object)
MemberwiseClone()

Crea una copia superficial del Object actual.

(Heredado de Object)
RaiseExceptionIfNecessary()

Genera una excepción proporcionada por el usuario si se ha producido un error en una operación asincrónica.

(Heredado de AsyncCompletedEventArgs)
ToString()

Devuelve una cadena que representa el objeto actual.

(Heredado de Object)

Se aplica a