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 

事件類型

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

備註

每次非同步作業將資源下載為字串完成時,就會引發此事件。 這些作業會藉由呼叫 DownloadStringAsync 方法來啟動。

DownloadStringCompletedEventHandler是這個事件的委派。 類別 DownloadStringCompletedEventArgs 會提供事件處理常式與事件資料。

如需如何處理事件的詳細資訊,請參閱 處理和引發事件

適用於