ThreadException doesn't fire with multiple threads/MessagePumps
From: Jason Goodwin (anonymous_at_discussions.microsoft.com)
Date: 03/22/04
- Next message: Tim Wilson: "Re: Tab Stops in DataGrid"
- Previous message: Daniel: "Help on listview issue!"
- Next in thread: Jason Goodwin: "RE: ThreadException doesn't fire with multiple threads/MessagePumps"
- Reply: Jason Goodwin: "RE: ThreadException doesn't fire with multiple threads/MessagePumps"
- Messages sorted by: [ date ] [ thread ]
Date: Mon, 22 Mar 2004 12:41:10 -0800
Hello,
I have a problem thats been driving me crazy.
I have an application that is hosting smaller applications within it. It runs each of these sub-applications on their own threads with their own MessagePumps created via Application.Run.
I'm attaching a handler to AppDomain.UnhandledException (for some other threads that are running in the background). I'm also attaching a handler to Application.ThreadException right before calling Application.Run with each sub-application's main form.
Occassionally, when an un-handled exception occurs (like in an event handler for a button) this exception misses the ThreadException event and passes through the AppDomain.UnhandledException event. This then nukes the Message Pump and thread that originated the exception resulting in the sub-application being killed. (ThreadExit for the application does run, but it seems that ThreadExit once applied happens for all threads with a pump?!?)
In trying to reproduce this in a prototype, I've found that the ThreadException event will occur in the child thread only if a a handler was attached in the hosting application's thread regardless of whether a method was called via Control.Invoke from the main thread, or whether it occurred in response to a button click. It just goes to the AppDomain.UnhandledException on the thread that originated the request.
(I would expect the Invoke'd method to be completely unhandled since it propagates back to the hosting app's thread, but when the exception completely originates in the sub-app's thread I would expect it to work.)
I've tried looking for more advanced documentation to find out what happens with more than one message pump thread and Application.ThreadException, but I just can't seem to find anything besides the raw basics of attaching a handler to it.
Can someone please point me in the proper direction to find out what is going on?
- Next message: Tim Wilson: "Re: Tab Stops in DataGrid"
- Previous message: Daniel: "Help on listview issue!"
- Next in thread: Jason Goodwin: "RE: ThreadException doesn't fire with multiple threads/MessagePumps"
- Reply: Jason Goodwin: "RE: ThreadException doesn't fire with multiple threads/MessagePumps"
- Messages sorted by: [ date ] [ thread ]