PowerTCP Mail for .NET
EndRead(IAsyncResult,Boolean) Method
See Also  Example Send comments on this topic.
Dart.PowerTCP.Mail Namespace > SegmentedStream Class > EndRead Method : EndRead(IAsyncResult,Boolean) Method




ar
Reference to the pending asynchronous request that is returned from BeginRead().
found
Reference to the BeginRead() 'found' parameter.
Ends a pending asynchronous SegmentedStream.BeginRead request (that uses a 'found' parameter).

Syntax

Visual Basic (Declaration) 
Public Overloads Function EndRead( _
   ByVal ar As IAsyncResult, _
   ByRef found As Boolean _
) As Integer
Visual Basic (Usage)Copy Code
Dim instance As SegmentedStream
Dim ar As IAsyncResult
Dim found As Boolean
Dim value As Integer
 
value = instance.EndRead(ar, found)
C# 
public int EndRead( 
   IAsyncResult ar,
   ref bool found
)
Managed Extensions for C++ 
public: int EndRead( 
   IAsyncResult* ar,
   ref bool found
) 
C++/CLI 
public:
int EndRead( 
   IAsyncResult^ ar,
   bool% found
) 

Parameters

ar
Reference to the pending asynchronous request that is returned from BeginRead().
found
Reference to the BeginRead() 'found' parameter.

Return Value

The number of bytes read from the stream and copied into the user's buffer. Will return 0 at the end of the stream to indicate the stream has closed and all data has been read.

Exceptions

ExceptionDescription
System.IO.IOExceptionThrown when the stream is not Readable.
System.ArgumentNullExceptionasyncResult is a null reference.
System.ArgumentExceptionasyncResult is not a valid reference.
System.IO.EndOfStreamException The end of the stream was found before the required byte count was received, or the end of the stream was found before the delimiter was found.
System.IO.InternalBufferOverflowException The delimiter was not found within the maximum number of bytes (count) specified.

Example

The following example demonstrates asynchronously reading from the server using the stream interface. This involves creating a callback method in which the response is handled. If you would like to use fully asynchronous methods with events already implemented, try the low-level interface (Tcp.BeginRead & Tcp.BeginWrite).
C#Copy Code
private void AsynchronousReadTest()
{
   // Connect to the server
   tcp1.Connect("atropos", 13);

   // DAYTIME protocol (port 13) sends data and closes, receive data.
   // This demonstrates receiving data asynchronously using the stream interface.
			
   // data buffer is a global variable
   databuffer = new byte[tcp1.ReceiveBufferSize];

   // Begin the asynchronous Read operation.
   tcp1.Stream.BeginRead(databuffer, 0, tcp1.ReceiveBufferSize, new System.AsyncCallback(MyCallback), null);
}

private void MyCallback(System.IAsyncResult ar)
{
   // End pending asynchronous request.
   if(ar.IsCompleted)
      tcp1.Stream.EndRead(ar);

   // Write result
   Debug.WriteLine(System.Text.Encoding.Default.GetString(databuffer));
}

Remarks

You will normally call this method from within your AsyncCallback event handler to complete your asynchronous read request, but it can be called anytime to cancel an outstanding request.

Requirements

Target Platforms: Microsoft .NET Framework 2.0

See Also

Documentation Version 3.2
© 2010 Dart Communications. All Rights Reserved.