UploadStringCompletedEventHandler 代理人
定義
重要
部分資訊涉及發行前產品,在發行之前可能會有大幅修改。 Microsoft 對此處提供的資訊,不做任何明確或隱含的瑕疵擔保。
代表將處理 UploadStringCompleted 之 WebClient 事件的方法。
public delegate void UploadStringCompletedEventHandler(System::Object ^ sender, UploadStringCompletedEventArgs ^ e);
public delegate void UploadStringCompletedEventHandler(object sender, UploadStringCompletedEventArgs e);
type UploadStringCompletedEventHandler = delegate of obj * UploadStringCompletedEventArgs -> unit
Public Delegate Sub UploadStringCompletedEventHandler(sender As Object, e As UploadStringCompletedEventArgs)
參數
- sender
- Object
事件的來源。
範例
下列程式代碼範例示範如何以異步方式上傳字串。
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
備註
建立 UploadStringCompletedEventHandler 委派時,必須識別處理事件的方法。 若要使事件與您的事件處理常式產生關聯,請將委派的執行個體 (Instance) 加入至事件。 除非您移除委派,否則每當事件發生時就會呼叫事件處理常式。 如需事件處理程式委派的詳細資訊,請參閱 處理和引發事件。
擴充方法
GetMethodInfo(Delegate) |
取得表示特定委派所代表之方法的物件。 |