UploadStringCompletedEventHandler Delegate


表示将处理 WebClientUploadStringCompleted 事件的方法。Represents the method that will handle the UploadStringCompleted event of a 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)



事件的源。The source of the event.


一个包含事件数据的 UploadStringCompletedEventArgsA UploadStringCompletedEventArgs containing event data.



下面的代码示例演示如何以异步方式上载字符串。The following code example demonstrates asynchronously uploading a string.

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

上传完成时,将调用以下方法。The following method is called when the upload completes.

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)
End Sub


创建 UploadStringCompletedEventHandler 委托时,需要标识将处理该事件的方法。When you create a UploadStringCompletedEventHandler delegate, you identify the method that will handle the event. 若要将事件与事件处理程序关联,请将该委托的一个实例添加到事件中。To associate the event with your event handler, add an instance of the delegate to the event. 除非移除了该委托,否则每当发生该事件时就会调用事件处理程序。The event handler is called whenever the event occurs, unless you remove the delegate. 有关事件处理程序委托的详细信息,请参阅处理和引发事件For more information about event handler delegates, see Handling and Raising Events.

Extension Methods


获取指示指定委托表示的方法的对象。Gets an object that represents the method represented by the specified delegate.

Applies to