DownloadDataCompletedEventArgs.Result Properti
Definisi
Penting
Beberapa informasi terkait produk prarilis yang dapat diubah secara signifikan sebelum dirilis. Microsoft tidak memberikan jaminan, tersirat maupun tersurat, sehubungan dengan informasi yang diberikan di sini.
Mendapatkan data yang diunduh oleh DownloadDataAsync metode .
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()
Nilai Properti
Array Byte yang berisi data yang diunduh.
Contoh
Contoh kode berikut menampilkan nilai properti ini.
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
Keterangan
Anda harus memeriksa Error properti dan Cancelled sebelum menggunakan data yang dikembalikan oleh properti ini.
Error Jika nilai properti adalah Exception objek atau Cancelled nilai properti adalah true
, operasi asinkron tidak selesai dengan benar dan Result nilai properti tidak akan valid.