DownloadDataCompletedEventArgs.Result 属性
定义
重要
一些信息与预发行产品相关,相应产品在发行之前可能会进行重大修改。 对于此处提供的信息,Microsoft 不作任何明示或暗示的担保。
获取由 DownloadDataAsync 方法下载的数据。
public:
property cli::array <System::Byte> ^ Result { cli::array <System::Byte> ^ get(); };
public byte[] Result { get; }
member this.Result : byte[]
Public ReadOnly Property Result As Byte()
属性值
Byte[]
包含已下载数据的 Byte 数组。
示例
下面的代码示例显示此属性的值。
void DownloadDataCallback( Object^ /*sender*/, DownloadDataCompletedEventArgs^ e )
{
System::Threading::AutoResetEvent^ waiter = dynamic_cast<System::Threading::AutoResetEvent^>(e->UserState);
try
{
// If the request was not canceled and did not throw
// an exception, display the resource.
if ( !e->Cancelled && e->Error == nullptr )
{
array<Byte>^data = dynamic_cast<array<Byte>^>(e->Result);
String^ textData = System::Text::Encoding::UTF8->GetString( data );
Console::WriteLine( textData );
}
}
finally
{
// Let the main application thread resume.
waiter->Set();
}
}
private static void DownloadDataCallback(Object sender, DownloadDataCompletedEventArgs e)
{
System.Threading.AutoResetEvent waiter = (System.Threading.AutoResetEvent)e.UserState;
try
{
// If the request was not canceled and did not throw
// an exception, display the resource.
if (!e.Cancelled && e.Error == null)
{
byte[] data = (byte[])e.Result;
string textData = System.Text.Encoding.UTF8.GetString(data);
Console.WriteLine(textData);
}
}
finally
{
// Let the main application thread resume.
waiter.Set();
}
}
Private Shared Sub DownloadDataCallback(ByVal sender As Object, ByVal e As DownloadDataCompletedEventArgs)
Dim waiter As System.Threading.AutoResetEvent = CType(e.UserState, System.Threading.AutoResetEvent)
Try
' If the request was not canceled and did not throw
' an exception, display the resource.
If e.Cancelled = False AndAlso e.Error Is Nothing Then
Dim data() As Byte = CType(e.Result, Byte())
Dim textData As String = System.Text.Encoding.UTF8.GetString(data)
Console.WriteLine(textData)
End If
Finally
' Let the main application thread resume.
waiter.Set()
End Try
End Sub
注解
在使用此属性返回的数据之前,应检查 Error 和 Cancelled 属性。
Error如果属性的值为 Exception 对象或Cancelled属性值为 true
,则异步操作未正确完成,Result并且属性的值将无效。