OpenWriteCompletedEventArgs.Result 屬性
定義
重要
部分資訊涉及發行前產品,在發行之前可能會有大幅修改。 Microsoft 對此處提供的資訊,不做任何明確或隱含的瑕疵擔保。
取得一個可寫入的串流,用來傳送資料到伺服器。
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 OpenWriteCallback2(Object sender, OpenWriteCompletedEventArgs e)
{
Stream body = null;
StreamWriter s = null;
try
{
body = (Stream)e.Result;
s = new StreamWriter(body);
s.AutoFlush = true;
s.Write("This is content data to be sent to the server.");
}
finally
{
if (s != null)
{
s.Close();
}
if (body != null)
{
body.Close();
}
}
}
Private Shared Sub OpenWriteCallback2(ByVal sender As Object, ByVal e As OpenWriteCompletedEventArgs)
Dim body As Stream = Nothing
Dim s As StreamWriter = Nothing
Try
body = CType(e.Result, Stream)
s = New StreamWriter(body)
s.AutoFlush = True
s.Write("This is content data to be sent to the server.")
Finally
If Not s Is Nothing Then
s.Close()
End If
If Not body Is Nothing Then
body.Close()
End If
End Try
End Sub
備註
使用該屬性回傳的串流前,應該先檢查 Error 和 Cancelled 屬性。 若屬性的值為Exception物件或Cancelled屬性值為 true,則Error非同步操作未正確完成,屬性Result值將不成立。