OpenReadCompletedEventArgs.Result 屬性
定義
重要
部分資訊涉及發行前產品,在發行之前可能會有大幅修改。 Microsoft 對此處提供的資訊,不做任何明確或隱含的瑕疵擔保。
取得包含由 DownloadDataAsync 方法下載之資料的可讀取資料流。
public:
property System::IO::Stream ^ Result { System::IO::Stream ^ get(); };
public System.IO.Stream Result { get; }
member this.Result : System.IO.Stream
Public ReadOnly Property Result As Stream
屬性值
Stream,包含下載的資料。
範例
下列程式代碼範例會使用這個屬性傳回的數據流。
private static void OpenReadCallback2(Object sender, OpenReadCompletedEventArgs e)
{
Stream reply = null;
StreamReader s = null;
try
{
reply = (Stream)e.Result;
s = new StreamReader(reply);
Console.WriteLine(s.ReadToEnd());
}
finally
{
if (s != null)
{
s.Close();
}
if (reply != null)
{
reply.Close();
}
}
}
Private Shared Sub OpenReadCallback2(ByVal sender As Object, ByVal e As OpenReadCompletedEventArgs)
Dim reply As Stream = Nothing
Dim s As StreamReader = Nothing
Try
reply = CType(e.Result, Stream)
s = New StreamReader(reply)
Console.WriteLine(s.ReadToEnd())
Finally
If Not s Is Nothing Then
s.Close()
End If
If Not reply Is Nothing Then
reply.Close()
End If
End Try
End Sub
備註
您應該先檢查 和 Cancelled 屬性,Error再使用這個屬性所傳回的數據。
Error如果屬性的值是Exception物件,或Cancelled屬性的值是 true,異步操作未正確完成,而且Result屬性值無效。