Debugging while using BackgroundWorker

In an earlier post I extolled the virtues of BackgroundWorker. One peculiarity of working with it is that exceptions thrown during DoWork can be difficult to track down since it's not executing on the UI creating thread.

Fortunately Visual Studio 2005 (and up I assume) has a way to catch pretty much any Managed Exception (along with many Unmanaged Exceptions) even if it's handled by user code (e.g., by the AppDomain unhandled exception event). Under Debug->Exceptions -> Common Language Runtime Exceptions you can choose which Exceptions you want to trap/enter the debugger by checking the checkbox in the "Thrown" column.

As soon as all such exceptions are thrown the debugger traps the exception.

This is a great way to catch those Exceptions that would otherwise go unnoticed. Those unnoticed Exceptions often linger for months then become full blooded Application Crashes so anything that helps find them early is imho a good thing :)

No comments:

Post a Comment