SslStream.EndWrite(IAsyncResult) 方法

定義

結束由先前呼叫 BeginWrite(Byte[], Int32, Int32, AsyncCallback, Object) 所開始的非同步寫入作業。

public:
 override void EndWrite(IAsyncResult ^ asyncResult);
public override void EndWrite (IAsyncResult asyncResult);
override this.EndWrite : IAsyncResult -> unit
Public Overrides Sub EndWrite (asyncResult As IAsyncResult)

參數

asyncResult
IAsyncResult

IAsyncResult 執行個體,由對 BeginWrite(Byte[], Int32, Int32, AsyncCallback, Object) 的呼叫所傳回。

例外狀況

asyncResultnull

asyncResult 不是由呼叫 BeginWrite(Byte[], Int32, Int32, AsyncCallback, Object) 的方式所建立。

不存在要完成的暫止寫入作業。

-或-

尚未執行驗證。

寫入作業失敗。

範例

下列程式碼範例示範結束非同步寫入作業。

void WriteCallback( IAsyncResult^ ar )
{
   ClientState^ state = dynamic_cast<ClientState^>(ar->AsyncState);
   SslStream^ stream = state->stream;
   try
   {
      Console::WriteLine( L"Writing data to the client." );
      stream->EndWrite( ar );
   }
   catch ( Exception^ writeException ) 
   {
      Console::WriteLine( L"Write error: {0}", writeException->Message );
      state->Close();
      return;
   }

   Console::WriteLine( L"Finished with client." );
   state->Close();
}
void WriteCallback(IAsyncResult ar)
{
    ClientState state = (ClientState) ar.AsyncState;
    SslStream stream = state.stream;
    try
    {
        Console.WriteLine("Writing data to the client.");
        stream.EndWrite(ar);
    }
    catch (Exception writeException)
    {
        Console.WriteLine("Write error: {0}",
            writeException.Message);
        state.Close();
        return;
    }
    Console.WriteLine("Finished with client.");
    state.Close();
}

備註

如果作業尚未完成,這個方法會封鎖直到它完成為止。

應用程式在成功驗證之前,無法呼叫這個方法。 若要進行驗證,請呼叫其中 AuthenticateAsClient 一個 、 或 BeginAuthenticateAsClientAuthenticateAsServer BeginAuthenticateAsServer 方法。

若要同步執行這項作業,請使用 Write 方法。

適用於