WebClient.DownloadStringCompleted Событие
Определение
Важно!
Некоторые сведения относятся к предварительной версии продукта, в которую до выпуска могут быть внесены существенные изменения. Майкрософт не предоставляет никаких гарантий, явных или подразумеваемых, относительно приведенных здесь сведений.
Происходит после завершения асинхронной операции по загрузке ресурса.
public:
event System::Net::DownloadStringCompletedEventHandler ^ DownloadStringCompleted;
public event System.Net.DownloadStringCompletedEventHandler? DownloadStringCompleted;
public event System.Net.DownloadStringCompletedEventHandler DownloadStringCompleted;
member this.DownloadStringCompleted : System.Net.DownloadStringCompletedEventHandler
Public Custom Event DownloadStringCompleted As DownloadStringCompletedEventHandler
Public Event DownloadStringCompleted As DownloadStringCompletedEventHandler
Тип события
Примеры
В следующем примере кода показано задание обработчика событий для этого события.
// 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
В следующем примере кода показана реализация обработчика для этого события.
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
Комментарии
Это событие возникает каждый раз, когда выполняется асинхронная операция загрузки ресурса по мере выполнения строки. Эти операции запускаются путем вызова DownloadStringAsync методов .
Является DownloadStringCompletedEventHandler делегатом для этого события. Класс DownloadStringCompletedEventArgs предоставляет обработчику событий данные события.
Дополнительные сведения об обработке событий см. в разделе Обработка и вызов событий.
Применяется к
Обратная связь
https://aka.ms/ContentUserFeedback.
Ожидается в ближайшее время: в течение 2024 года мы постепенно откажемся от GitHub Issues как механизма обратной связи для контента и заменим его новой системой обратной связи. Дополнительные сведения см. в разделеОтправить и просмотреть отзыв по