WebClient.UploadStringCompleted 事件
定義
重要
部分資訊涉及發行前產品,在發行之前可能會有大幅修改。 Microsoft 對此處提供的資訊,不做任何明確或隱含的瑕疵擔保。
發生於異步字串上傳作業完成時。
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
事件類型
範例
下列程式代碼範例示範如何設定此事件的事件處理程式。
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
下列程式代碼範例示範此事件的處理程序實作。
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
備註
謹慎
WebRequest
、HttpWebRequest
、ServicePoint
和 WebClient
已經過時,您不應該將它們用於新的開發。 請改用 HttpClient。
每次異步字串上傳作業完成時,都會引發此事件。 異步字串上傳的啟動方式是呼叫 UploadStringAsync 方法。
UploadStringCompletedEventHandler 是這個事件的委派。 UploadStringCompletedEventArgs 類別會提供事件處理程式與事件數據。
如需如何處理事件的詳細資訊,請參閱 處理和引發事件。