Finding "First chance exceptions"

InertiaM

Well-known member
Joined
Nov 3, 2007
Messages
663
Location
Kent, UK
Programming Experience
10+
I've been trying to eradicate all first chance exceptions, to ensure all errors are properly accounted for. However, when I close my program, I still have two First Chance exceptions :-

A first chance exception of type 'System.Threading.ThreadAbortException' occurred in System.dll
A first chance exception of type 'System.Threading.ThreadAbortException' occurred in (program name)

As far as I knew, all my many threads are closed properly, but obviously not. I have tried to find the 'error' by using breakpoints, but to no avail. I tried setting Debug - Exceptions - CLR Exceptions - System.Threading - Thrown to Checked, but this doesnt fire.

I know First Chance exceptions are not awful, but given that some of my threads involve COM port communication, it would be good to close all thread properly, hence trying to find them.

Suggestions please :tennis:
 
Try to check Thrown for MDA AsynchronousThreadAbort. There should be a Thread.Abort call in your code causing it.
 
Thanks JohnH. Yes, you were right. Not sure how to fix it though, as the thread being aborted has a UDP blocking call on it. Will do some research :)
 
Turned out it wasnt the COM port thread, it was a UDP listening thread - which I had written with a blocking Receive method rather than asynchronous BeginReceive method.

Am going to rewrite it using code from this jmcilhinney reply
 
Remember to close the UDPClient before releasing it, this will also trigger the current BeginReceive callback, where now socket is Nothing and you can check Client property for this before attempting to EndReceive.
 
Back
Top