DownloadStringCompletedEventArgs DownloadStringCompletedEventArgs DownloadStringCompletedEventArgs DownloadStringCompletedEventArgs Class

Определение

Предоставляет данные для события DownloadStringCompleted.Provides data for the DownloadStringCompleted event.

public ref class DownloadStringCompletedEventArgs : System::ComponentModel::AsyncCompletedEventArgs
public class DownloadStringCompletedEventArgs : System.ComponentModel.AsyncCompletedEventArgs
type DownloadStringCompletedEventArgs = class
    inherit AsyncCompletedEventArgs
Public Class DownloadStringCompletedEventArgs
Inherits AsyncCompletedEventArgs
Наследование
DownloadStringCompletedEventArgsDownloadStringCompletedEventArgsDownloadStringCompletedEventArgsDownloadStringCompletedEventArgs

Примеры

В следующем примере кода демонстрируется асинхронная загрузка строки.The following code example demonstrates downloading a string asynchronously.

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

При завершении загрузки вызывается следующий метод.The following method is called when the download completes.

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

Комментарии

Экземпляры этого класса передаются в DownloadStringCompletedEventHandler.Instances of this class are passed to the DownloadStringCompletedEventHandler.

Свойства

Cancelled Cancelled Cancelled Cancelled

Возвращает значение, показывающее, была ли отменена асинхронная операция.Gets a value indicating whether an asynchronous operation has been canceled.

(Inherited from AsyncCompletedEventArgs)
Error Error Error Error

Возвращает значение, показывающее, какая ошибка произошла в течение асинхронной операции.Gets a value indicating which error occurred during an asynchronous operation.

(Inherited from AsyncCompletedEventArgs)
Result Result Result Result

Получает данные, загруженные методом DownloadStringAsync.Gets the data that is downloaded by a DownloadStringAsync method.

UserState UserState UserState UserState

Возвращает уникальный идентификатор для асинхронной задачи.Gets the unique identifier for the asynchronous task.

(Inherited from AsyncCompletedEventArgs)

Методы

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

Определяет, равен ли заданный объект текущему объекту.Determines whether the specified object is equal to the current object.

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

Служит хэш-функцией по умолчанию.Serves as the default hash function.

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

Возвращает объект Type для текущего экземпляра.Gets the Type of the current instance.

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

Создает неполную копию текущего объекта Object.Creates a shallow copy of the current Object.

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

Вызывает предоставленное пользователем исключение в случае неудачного выполнения асинхронной операции.Raises a user-supplied exception if an asynchronous operation failed.

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

Возвращает строку, представляющую текущий объект.Returns a string that represents the current object.

(Inherited from Object)

Применяется к