DownloadDataCompletedEventArgs.Result 屬性

定義

取得 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

備註

您應該先檢查 和 Cancelled 屬性, Error 再使用此屬性所傳回的資料。 Error如果屬性值為 Exception 物件,或 Cancelled 屬性值為 true ,則非同步作業未正確完成,且 Result 屬性值無效。

適用於