I am stuck in a debugging scenario and I need help understanding how I might get more information about what is happening to my application.
The exception is thrown when I close the main form, seemingly during the last bit of processing prior to complete shut-down.
I get one of the two following exceptions, with no obvious reason why one or the other. I can simply open the app and immediately close it. One of the two will be generated. If there's a catch, it's probably that #2 appears to be more likely if I focus another running application, return to mine, and then close it.
Exception #1:
Cannot access a disposed object.
Object name: 'System.Net.Sockets.NetworkStream'.
at System.Net.Sockets.NetworkStream.Write(Byte[] buffer, Int32 offset, Int32 size)
Exception #2:
Safe handle has been closed
System.Net.UnsafeNclNativeMethods.OSSOCK.WSAEventSelect(SafeCloseSocket socketHandle, IntPtr Event, AsyncEventBits NetworkEvents)
There are two direct uses of Sockets in my application.
1) A UDPClient listener is established on a BackgroundWorker
. Just a little thing we use internally to monitor database hits.
2) An HttpWebRequest that calls out to our website and gets some information.
Both of these have been in play for a while without issue, and without being changed, so I suspect they aren't guilty.
Because this is a client-server database application, there is a lot of network traffic going on, and it's possible that the database engine is where this is happening. I just don't know, and that where I need help.
Packet/traffic sniffer? Settings/setup in Visual Studio to get better information about the exception? How would you go about tracking this down?