I just went through 2 hours of painful troubleshooting my devenv thinking the loading of debug symbols had broken.
Whenever I ran my test a couple of breakpoints would hit and then suddenly it would quit the test with a positive result.

Whut?! I thought.. then reminded myself that perhaps the debug symbols didn’t get correctly loaded and troubleshooted.
Finally I took a good look at the output the testrunner generated:

The thread ‘Agent: state execution thread for test ‘CanWriteStatistics’ ….
A first chance exception of type ‘System.Threading.ThreadAbortException’ occurred in mscorlib.dll
An exception of type ‘System.Threading.ThreadAbortException’ occurred in mscorlib.dll but was not handled in user code
The thread ‘Agent: heartbeat thread’ (0x1444) has exited with code 0 (0x0).
The thread ” (0x1ad4) has exited with code 0 (0x0).
The program ‘[6392] QTAgent32.exe: Managed (v4.0.30319)’ has exited with code 0 (0x0).
The program ‘[4548] MyProject.vshost.exe: Managed (v2.0.50727)’ has exited with code 0 (0x0).

So there┬┤s an exception!? Why isn’t it caught?
Then it dawned on me. I had just implemented the use of a BackgroundWorker!
Obviously I hadn’t implemented a handler for the BackgroundWorker.RunWorkerCompleted, the method that
allows you to handle any exception that has occured and furthermore my test just consisted of executing the
method that used the worker. Of course it would complete with success since the test wouldn’t even wait for
the async method to finish.

So to conclude:

  • Beware of threads! ­čÖé
  • Always make the underlying use of async operations transparent, naming ExportToAsync instead of ExportTo
  • Always implement Finished-event handlers and make sure to propagate/handle exceptions!
  • Make use of the output window
Why not join the newsletter?

Why not join the newsletter?

If you're not a fan of facebook or twitter, sign up to the newsletter and I'll send you a quick update every so often with what's going on and new posts coming out.

You have Successfully Subscribed!