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 委托时,需要标识将处理该事件的方法。 若要将事件与事件处理程序关联,请将该委托的一个实例添加到事件中。 除非移除了该委托,否则每当发生该事件时就会调用事件处理程序。 有关事件处理程序委托的详细信息,请参阅 处理和引发事件。
扩展方法
GetMethodInfo(Delegate) |
获取指示指定委托表示的方法的对象。 |