- ar
- A IAsyncResult object that holds the state information for the asynchronous operation.
Type Reason ArgumentNullException asyncResult is null. System.IO.IOException Note: This method catches all exceptions thrown by the Socket.EndSend(IAsyncResult) method.ObjectDisposedException The current instance has been disposed.
NetworkStream.EndWrite(IAsyncResult) completes the asynchronous send operation started in NetworkStream.BeginWrite(Byte[], int, int, AsyncCallback, object).
Before calling NetworkStream.BeginWrite(Byte[], int, int, AsyncCallback, object), you need to create a callback method that implements the AsyncCallback delegate. This callback method executes in a separate thread and is called by the system after NetworkStream.BeginWrite(Byte[], int, int, AsyncCallback, object) returns. The callback method must accept the IAsyncResult returned from the NetworkStream.BeginWrite(Byte[], int, int, AsyncCallback, object) method as a parameter.
Within the callback method, call the IAsyncResult.AsyncState property of the IAsyncResult parameter to obtain the System.Net.Sockets.NetworkStream. After obtaining the System.Net.Sockets.NetworkStream, you can call the NetworkStream.EndWrite(IAsyncResult) method to successfully complete the send operation and return the number of bytes sent.
The NetworkStream.EndWrite(IAsyncResult) method blocks until the requested number of bytes are sent.
If you receive an System.IO.IOException, check the Exception.InnerException property to determine if it was caused by a System.Net.Sockets.SocketException. If so, use the SocketException.ErrorCode property to obtain the specific error code, and refer to the Windows Sockets version 2 API error code documentation in MSDN for a detailed description of the error.