WebClient.UploadDataCompleted Event
Definition
Important
Some information relates to prerelease product that may be substantially modified before it’s released. Microsoft makes no warranties, express or implied, with respect to the information provided here.
Occurs when an asynchronous data-upload operation completes.
public:
event System::Net::UploadDataCompletedEventHandler ^ UploadDataCompleted;
public event System.Net.UploadDataCompletedEventHandler? UploadDataCompleted;
public event System.Net.UploadDataCompletedEventHandler UploadDataCompleted;
member this.UploadDataCompleted : System.Net.UploadDataCompletedEventHandler
Public Custom Event UploadDataCompleted As UploadDataCompletedEventHandler
Public Event UploadDataCompleted As UploadDataCompletedEventHandler
Event Type
Examples
The following code example demonstrates setting an event handler for this event.
void UploadDataInBackground3( String^ address )
{
WebClient^ client = gcnew WebClient;
Uri ^uri = gcnew Uri(address);
String^ text = "Time = 12:00am temperature = 50";
array<Byte>^data = System::Text::Encoding::UTF8->GetBytes( text );
client->UploadDataCompleted += gcnew UploadDataCompletedEventHandler( UploadDataCallback3 );
client->UploadDataAsync( uri, data );
}
public static void UploadDataInBackground3(string address)
{
WebClient client = new WebClient();
Uri uri = new Uri(address);
string text = "Time = 12:00am temperature = 50";
byte[] data = System.Text.Encoding.UTF8.GetBytes(text);
client.UploadDataCompleted += new UploadDataCompletedEventHandler(UploadDataCallback3);
client.UploadDataAsync(uri, data);
}
Public Shared Sub UploadDataInBackground3(ByVal address As String)
Dim client As WebClient = New WebClient()
Dim text As String = "Time = 12:00am temperature = 50"
Dim data() As Byte = System.Text.Encoding.UTF8.GetBytes(text)
AddHandler client.UploadDataCompleted, AddressOf UploadDataCallback3
Dim uri as Uri = New Uri(address)
client.UploadDataAsync(uri, data)
End Sub
The following code example shows an implementation of a handler for this event.
void UploadDataCallback3( Object^ /*sender*/, UploadDataCompletedEventArgs^ e )
{
array<Byte>^data = dynamic_cast<array<Byte>^>(e->Result);
String^ reply = System::Text::Encoding::UTF8->GetString( data );
Console::WriteLine( reply );
}
private static void UploadDataCallback3(Object sender, UploadDataCompletedEventArgs e)
{
byte[] data = (byte[])e.Result;
string reply = System.Text.Encoding.UTF8.GetString(data);
Console.WriteLine(reply);
}
Private Shared Sub UploadDataCallback3(ByVal sender As Object, ByVal e As UploadDataCompletedEventArgs)
Dim data() As Byte = CType(e.Result, Byte())
Dim reply As String = System.Text.Encoding.UTF8.GetString(data)
Console.WriteLine(reply)
End Sub
Remarks
This event is raised each time an asynchronous data upload operation completes. Asynchronous data uploads are started by calling the UploadDataAsync methods.
The UploadDataCompletedEventHandler is the delegate for this event. The UploadDataCompletedEventArgs class provides the event handler with event data.
For more information about how to handle events, see Handling and Raising Events.
Applies to
反馈
https://aka.ms/ContentUserFeedback。
即将发布:在整个 2024 年,我们将逐步淘汰作为内容反馈机制的“GitHub 问题”,并将其取代为新的反馈系统。 有关详细信息,请参阅:提交和查看相关反馈