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 A 裡面包含下載的資料。
範例
以下程式碼範例使用了此屬性回傳的串流。
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
備註
你應該先檢查 Error 和 Cancelled 屬性,再使用這個屬性回傳的資料。 若屬性的值為Exception物件或Cancelled屬性值為 true,則Error非同步操作未正確完成,屬性Result值將不成立。