C# 1.1: Monitoring worker threads

cmultithreadingnet

Using the .Net Framework 1.1, what options are available for monitoring threads from other threads? I am attempting to deal with a shortcoming of the threading implementation in 1.1 wherein unhandled exceptions will cause threads to die silently. In 2.0 and later this had been corrected so that any unhandled exception on any thread will cause the entire application to die, I beleive.

When threads in my application die, I would like to retrieve as much context as possible from the main thread: the method they were executing, a stack trace, etc. I can determine when they die but retrieving context has proven difficult. I have tried registering a handler for the AppDomain.CurrentDomain.UnhandledException event. But I am not getting called back when events occur. This is probably due to a limitation with the API I'm developing for.

Besides this event, what options are available to get context from threads as they die on another thread?

Best Answer

How are you creating these threads? Are you adding a delegate to the thread pool? IF so, you could create a wrapper method that takes the delegate provided and wraps another delegate around it which takes care of your try / catch, and then adds that new delegate to the thread pool queue. That way you could put in your error handling code in that second delegate.

Related Topic