Basically, in my Tcp Library I'm working on, whenever the system is told to "Stop", the OnClientConnected() Routine fires off, which is only raised under two circumstances:

  1. When a Client connects (obviously)
  2. When the server is told to shutdown


Now, the first one is handled just fine. But the second one is not. In fact, it has caused me a great deal of headache because it keeps throwing exceptions on this line in particular:

Code:
Dim _tcpClient As System.Net.Sockets.TcpClient = _tcpListener.EndAcceptTcpClient(IR)
When I hover over while debugging, I can see a few members that reveal exception data I could utilize; but unfortunately those members are private and I don't want to utilize reflection unless I have to since it could slow down performance where there may not be a real reason to.

I have thought of writing in a Boolean check to see if the server received a shutdown signal and that would indicate that it's time to not accept anything, but I want to avoid that if possible.

Is there any way to see if the TcpListener is no longer accepting connections and has had .Stop() called without reverting to catching the ObjectDisposedException that is raised? (because the Socket that is "accepted" is actually a disposed one)