ASP.NET Hosting

How to handle unhandled exceptions in Windows Forms

If you've already handled unhandled exceptions in your Windows Forms applications, your probably know the Application.ThreadException event.
This event is simple to use, but cannot be used to handle exceptions thrown in threads other than the main thread.
If you are working with multiple threads, you can take a look at this short article that shows how to handle unhandled exceptions for multithreaded Windows Forms applications.

2 Comments

  • Another catch is that the ThreadException event isn't static in the sense you think it is. If you have an app with multiple UI threads (create a new thread and invoke Application.Run on it), you have to add a delegate to the Application.ThreadException event in each of those threads to be able to handle it.

  • That's right, if you take a look at the ThreadException event with Reflector, you'll notice that it is stored by "ThreadContext".

Comments have been disabled for this content.