Bagikan melalui


WebClient.UploadStringCompleted Kejadian

Definisi

Terjadi ketika operasi unggahan string asinkron selesai.

public:
 event System::Net::UploadStringCompletedEventHandler ^ UploadStringCompleted;
public event System.Net.UploadStringCompletedEventHandler? UploadStringCompleted;
public event System.Net.UploadStringCompletedEventHandler UploadStringCompleted;
member this.UploadStringCompleted : System.Net.UploadStringCompletedEventHandler 
Public Custom Event UploadStringCompleted As UploadStringCompletedEventHandler 
Public Event UploadStringCompleted As UploadStringCompletedEventHandler 

Jenis Acara

Contoh

Contoh kode berikut menunjukkan pengaturan penanganan aktivitas untuk kejadian ini.

void UploadStringInBackground2( String^ address )
{
   WebClient^ client = gcnew WebClient;
   Uri ^uri = gcnew Uri(address);
   String^ data = "Time = 12:00am temperature = 50";

   client->UploadStringCompleted += gcnew UploadStringCompletedEventHandler( UploadStringCallback2 );
   client->UploadStringAsync( uri, data );
}
public static void UploadStringInBackground2(string address)
{
    WebClient client = new WebClient();
    Uri uri = new Uri(address);
    string data = "Time = 12:00am temperature = 50";
    client.UploadStringCompleted += new UploadStringCompletedEventHandler(UploadStringCallback2);
    client.UploadStringAsync(uri, data);
}
Public Shared Sub UploadStringInBackground2(ByVal address As String)

    Dim client As WebClient = New WebClient()
    Dim data As String = "Time = 12:00am temperature = 50"
    AddHandler client.UploadStringCompleted, AddressOf UploadStringCallback2
                Dim uri as Uri = New Uri(address)
    client.UploadStringAsync(uri, data)
End Sub

Contoh kode berikut menunjukkan implementasi handler untuk kejadian ini.

void UploadStringCallback2( Object^ /*sender*/, UploadStringCompletedEventArgs^ e )
{
   String^ reply = dynamic_cast<String^>(e->Result);
   Console::WriteLine( reply );
}
private static void UploadStringCallback2(Object sender, UploadStringCompletedEventArgs e)
{
    string reply = (string)e.Result;
    Console.WriteLine(reply);
}
Private Shared Sub UploadStringCallback2(ByVal sender As Object, ByVal e As UploadStringCompletedEventArgs)
    Dim reply As String = CStr(e.Result)
    Console.WriteLine(reply)
End Sub

Keterangan

Hati

WebRequest, HttpWebRequest, ServicePoint, dan WebClient usang, dan Anda tidak boleh menggunakannya untuk pengembangan baru. Gunakan HttpClient sebagai gantinya.

Kejadian ini dinaikkan setiap kali operasi pengunggah untai (karakter) asinkron selesai. Unggahan string asinkron dimulai dengan memanggil metode UploadStringAsync.

UploadStringCompletedEventHandler adalah delegasi untuk peristiwa ini. Kelas UploadStringCompletedEventArgs menyediakan penanganan aktivitas dengan data peristiwa.

Untuk informasi selengkapnya tentang cara menangani peristiwa, lihat Menangani dan Meningkatkan Peristiwa.

Berlaku untuk