"Dinsdale" <(E-Mail Removed)> wrote:
> I am trying to write a Tcp "Server" that opens a class that wraps a tcp
> socket when a new connection is made (Listener.AcceptSocket()).
> Everything is going swimmingly except when I try to close the socket
> during a read and I get the following error:
>
> <error_msg>
> An unhandled exception of type 'System.Net.Sockets.SocketException'
> occurred in system.dll
>
> Additional information: The I/O operation has been aborted because of
> either a thread exit or an application request
> </error_msg>
[snip]
> int intByteCount = _socClient.EndReceive(ar);//**** - THIS
> IS WHERE I GET MY EXCEPTION
[snip]
> I thought that maybe I can manually call the EndReceive function from
> the Close() routine but I cannot declare a IAsyncResult object. Any
> suggestions to close the connection would be great.
From my somewhat limited experience with async sockets, there are two
things interacting here. First, interrupting a blocking call like
Receive (if you weren't using async sockets) from another thread would
result in an exception being thrown - that just happens to be how the
..NET Socket class communicates the interruption at the Winsock level.
The second thing is that exceptions thrown from an asynchronous
operation get delayed until the call to the End* method. So, you only
get notification of the interruption when you call EndReceive().
Basically, what you're seeing is normal behaviour, AFAIK. You've got to
be prepared to catch the exception thrown when and where you call
EndReceive().
> Once again, thank you to the Google community for saving my behind.
> I'll try to answer a couple of other messages in return.
Believe it or not, this is the Microsoft community

These newsgroups
are hosted on Microsoft's servers (NNTP on news.microsoft.com), and get
mirrored to Usenet. Google Groups is a web-based interface to Usenet (as
well as having its own, non-Usenet, groups).
-- Barry
--
http://barrkel.blogspot.com/