OpenReadCompletedEventArgs Classe

Definizione

Fornisce dati per l'evento 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
Ereditarietà
OpenReadCompletedEventArgs

Esempi

Nell'esempio di codice riportato di seguito viene illustrato il download di una risorsa per la lettura.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

Il metodo seguente viene chiamato al termine del download.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

Commenti

Le istanze di questa classe vengono passate OpenReadCompletedEventHandler ai metodi.Instances of this class are passed to OpenReadCompletedEventHandler methods.

Proprietà

Cancelled

Ottiene un valore che indica se un'operazione asincrona è stata annullata.Gets a value indicating whether an asynchronous operation has been canceled.

(Ereditato da AsyncCompletedEventArgs)
Error

Ottiene un valore che indica l'errore verificatosi durante un'operazione asincrona.Gets a value indicating which error occurred during an asynchronous operation.

(Ereditato da AsyncCompletedEventArgs)
Result

Ottiene un flusso di lettura in cui sono contenuti i dati scaricati da un metodo DownloadDataAsync.Gets a readable stream that contains data downloaded by a DownloadDataAsync method.

UserState

Ottiene l’identificatore univoco per l'attività asincrona.Gets the unique identifier for the asynchronous task.

(Ereditato da AsyncCompletedEventArgs)

Metodi

Equals(Object)

Determina se l'oggetto specificato è uguale all'oggetto corrente.Determines whether the specified object is equal to the current object.

(Ereditato da Object)
GetHashCode()

Funge da funzione hash predefinita.Serves as the default hash function.

(Ereditato da Object)
GetType()

Ottiene l'oggetto Type dell'istanza corrente.Gets the Type of the current instance.

(Ereditato da Object)
MemberwiseClone()

Crea una copia superficiale dell'oggetto Object corrente.Creates a shallow copy of the current Object.

(Ereditato da Object)
RaiseExceptionIfNecessary()

Genera un'eccezione fornita dall'utente in caso di errore in un'operazione asincrona.Raises a user-supplied exception if an asynchronous operation failed.

(Ereditato da AsyncCompletedEventArgs)
ToString()

Restituisce una stringa che rappresenta l'oggetto corrente.Returns a string that represents the current object.

(Ereditato da Object)

Si applica a