Share via


OpenWriteCompletedEventArgs.Result 属性

定义

获取用于向服务器发送数据的可写流。

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 OpenWriteCallback2( Object^ /*sender*/, OpenWriteCompletedEventArgs^ e )
{
   Stream^ body = nullptr;
   StreamWriter^ s = nullptr;
   try
   {
      body = dynamic_cast<Stream^>(e->Result);
      s = gcnew StreamWriter( body );
      s->AutoFlush = true;
      s->Write( "This is content data to be sent to the server." );
   }
   finally
   {
      if ( s != nullptr )
      {
         s->Close();
      }
      if ( body != nullptr )
      {
         body->Close();
      }
   }

}
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 属性。 Error如果属性的值为 Exception 对象或Cancelled属性的值为 true,则异步操作未正确完成,Result并且该属性的值将无效。

适用于