OpenReadCompletedEventArgs OpenReadCompletedEventArgs OpenReadCompletedEventArgs OpenReadCompletedEventArgs Class

Définition

Fournit des données pour l'événement OpenReadCompleted.Provides data for the OpenReadCompleted event.

public ref class OpenReadCompletedEventArgs : System::ComponentModel::AsyncCompletedEventArgs
public class OpenReadCompletedEventArgs : System.ComponentModel.AsyncCompletedEventArgs
type OpenReadCompletedEventArgs = class
    inherit AsyncCompletedEventArgs
Public Class OpenReadCompletedEventArgs
Inherits AsyncCompletedEventArgs
Héritage
OpenReadCompletedEventArgsOpenReadCompletedEventArgsOpenReadCompletedEventArgsOpenReadCompletedEventArgs

Exemples

L’exemple de code suivant illustre le téléchargement d’une ressource pour la lecture.The following code example demonstrates downloading a resource for reading.

void OpenResourceForReading2( String^ address )
{
   WebClient^ client = gcnew WebClient;
   Uri ^uri = gcnew Uri(address);

   client->OpenReadCompleted += gcnew OpenReadCompletedEventHandler( OpenReadCallback2 );
   client->OpenReadAsync( uri );
}


public static void OpenResourceForReading2 (string address)
{
    WebClient client = new WebClient ();
    Uri uri = new Uri(address);

    client.OpenReadCompleted += new OpenReadCompletedEventHandler(OpenReadCallback2);
    client.OpenReadAsync (uri);
}

Public Shared Sub OpenResourceForReading2(ByVal address As String)

	Dim client As WebClient = New WebClient()
	AddHandler client.OpenReadCompleted, AddressOf OpenReadCallback2
                      Dim uri as Uri = New Uri(address)
	client.OpenReadAsync(uri)                        
End Sub

La méthode suivante est appelée lorsque le téléchargement terminé.The following method is called when the download completes.

void OpenReadCallback2( Object^ /*sender*/, OpenReadCompletedEventArgs^ e )
{
   Stream^ reply = nullptr;
   StreamReader^ s = nullptr;
   try
   {
      reply = dynamic_cast<Stream^>(e->Result);
      s = gcnew StreamReader( reply );
      Console::WriteLine( s->ReadToEnd() );
   }
   finally
   {
      if ( s != nullptr )
      {
         s->Close();
      }
      if ( reply != nullptr )
      {
         reply->Close();
      }
   }

}


private static void OpenReadCallback2 (Object sender, OpenReadCompletedEventArgs e)
{
    Stream reply = null;
    StreamReader s = null;

    try
    {
        reply = (Stream)e.Result;
        s = new StreamReader (reply);
        Console.WriteLine (s.ReadToEnd ());
    }
    finally
    {
        if (s != null)
        {
            s.Close ();
        }

        if (reply != null)
        {
            reply.Close ();
        }
    }
}

Private Shared Sub OpenReadCallback2(ByVal sender As Object, ByVal e As OpenReadCompletedEventArgs)

    Dim reply As Stream = Nothing
    Dim s As StreamReader = Nothing

    Try

        reply = CType(e.Result, Stream)
        s = New StreamReader(reply)
        Console.WriteLine(s.ReadToEnd())
    Finally

        If Not s Is Nothing Then

            s.Close()
        End If

        If Not reply Is Nothing Then

            reply.Close()
        End If
    End Try
End Sub

Remarques

Instances de cette classe sont passées à OpenReadCompletedEventHandler méthodes.Instances of this class are passed to OpenReadCompletedEventHandler methods.

Propriétés

Cancelled Cancelled Cancelled Cancelled

Obtient une valeur qui indique si une opération asynchrone a été annulée.Gets a value indicating whether an asynchronous operation has been canceled.

(Inherited from AsyncCompletedEventArgs)
Error Error Error Error

Obtient une valeur qui indique quelle erreur s'est produite pendant une opération asynchrone.Gets a value indicating which error occurred during an asynchronous operation.

(Inherited from AsyncCompletedEventArgs)
Result Result Result Result

Obtient un flux lisible qui contient des données téléchargées par une méthode DownloadDataAsync.Gets a readable stream that contains data downloaded by a DownloadDataAsync method.

UserState UserState UserState UserState

Obtient l'identificateur unique de la tâche asynchrone.Gets the unique identifier for the asynchronous task.

(Inherited from AsyncCompletedEventArgs)

Méthodes

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

Détermine si l'objet spécifié est identique à l'objet actuel.Determines whether the specified object is equal to the current object.

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

Fait office de fonction de hachage par défaut.Serves as the default hash function.

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

Obtient le Type de l'instance actuelle.Gets the Type of the current instance.

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

Crée une copie superficielle de l'objet Object actuel.Creates a shallow copy of the current Object.

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

Lève une exception fournie par l'utilisateur en cas d'échec d'une opération asynchrone.Raises a user-supplied exception if an asynchronous operation failed.

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

Retourne une chaîne qui représente l'objet actuel.Returns a string that represents the current object.

(Inherited from Object)

S’applique à