How to cancel a pending BeginReceive ?

  • Thread starter Thread starter Lee Gillie
  • Start date Start date
L

Lee Gillie

What is the proper way to cancel a pending BeginReceive/EndReceive ?
Can it be done without generating an exception ?

Currently I shutdown and close the socket. The blocking "EndReceive"
throws System.ObjectDisposedException.

I try to avoid throwing exceptions when ever possible, and reserve
them for unanticipated problems. Trying to stop a background
read/process loop is an anticipated activity. For me the debugger
delays 15 seconds when ever an exception is thrown. But regardless, I
am hoping for a cleaner approach. I can not find guidance on this
issue in framework documentation.

Forgive the cross posts. It would be nice to have a specific
framework/network related NG.

Thanks for any insight - Best regards - Lee Gillie - Spokane, WA
 
Ok, experimentation shows this seems to be the trick...

Do a shutdown on the socket.
EndReceive completes with zero bytes
I need to WAIT for this occur before shutdown thread then does a
close, otherwise the exception
 
Back
Top