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,包含已下载的数据。
示例
下面的代码示例使用此属性返回的流。
void OpenReadCallback2( Object^ /*sender*/, OpenReadCompletedEventArgs^ e )
{
Stream^ reply = nullptr;
StreamReader^ s = nullptr;
try
{
reply = dynamic_cast<Stream^>(e->Result);
s = gcnew StreamReader( reply );
Console::WriteLine( s->ReadToEnd() );
}
finally
{
if ( s != nullptr )
{
s->Close();
}
if ( reply != nullptr )
{
reply->Close();
}
}
}
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 属性。
Error如果属性的值为 Exception 对象或Cancelled属性的值为 true
,则异步操作未正确完成,Result并且该属性的值将无效。