UploadDataCompletedEventArgs 类
定义
重要
一些信息与预发行产品相关,相应产品在发行之前可能会进行重大修改。 对于此处提供的信息,Microsoft 不作任何明示或暗示的担保。
为 UploadDataCompleted 事件提供数据。
public ref class UploadDataCompletedEventArgs : System::ComponentModel::AsyncCompletedEventArgs
public class UploadDataCompletedEventArgs : System.ComponentModel.AsyncCompletedEventArgs
type UploadDataCompletedEventArgs = class
inherit AsyncCompletedEventArgs
Public Class UploadDataCompletedEventArgs
Inherits AsyncCompletedEventArgs
- 继承
示例
下面的代码示例演示如何异步上传数据。
void UploadDataInBackground2( 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 );
String^ method = "POST";
client->UploadDataCompleted += gcnew UploadDataCompletedEventHandler( UploadDataCallback2 );
client->UploadDataAsync( uri, method, data );
}
public static void UploadDataInBackground2(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);
string method = "POST";
client.UploadDataCompleted += new UploadDataCompletedEventHandler(UploadDataCallback2);
client.UploadDataAsync(uri, method, data);
}
Public Shared Sub UploadDataInBackground2(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)
Dim method As String = "POST"
AddHandler client.UploadDataCompleted, AddressOf UploadDataCallback2
Dim uri as Uri = New Uri(address)
client.UploadDataAsync(uri, method, data)
End Sub
上传完成后,将调用以下方法。
void UploadDataCallback2( 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 UploadDataCallback2(Object sender, UploadDataCompletedEventArgs e)
{
byte[] data = (byte[])e.Result;
string reply = System.Text.Encoding.UTF8.GetString(data);
Console.WriteLine(reply);
}
Private Shared Sub UploadDataCallback2(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
注解
此类的实例将传递给 UploadDataCompletedEventHandler。
属性
Cancelled |
获取一个值,该值指示异步操作是否已被取消。 (继承自 AsyncCompletedEventArgs) |
Error |
获取一个值,该值指示异步操作期间发生的错误。 (继承自 AsyncCompletedEventArgs) |
Result |
获取通过调用 UploadDataAsync 方法启动的数据上载操作的服务器回复。 |
UserState |
获取异步任务的唯一标识符。 (继承自 AsyncCompletedEventArgs) |
方法
Equals(Object) |
确定指定对象是否等于当前对象。 (继承自 Object) |
GetHashCode() |
作为默认哈希函数。 (继承自 Object) |
GetType() |
获取当前实例的 Type。 (继承自 Object) |
MemberwiseClone() |
创建当前 Object 的浅表副本。 (继承自 Object) |
RaiseExceptionIfNecessary() |
如果异步操作失败,则引发用户提供的异常。 (继承自 AsyncCompletedEventArgs) |
ToString() |
返回表示当前对象的字符串。 (继承自 Object) |