Reputation: 1959
I am able to print a stack trace of a thread which has caught an exception at runtime. I also need to print a trace of other threads running within the same process. I'm interested in finding a good way to freeze all threads as soon as the exception is caught in one thread.
For now, all i can do is query for each active thread then SuspendThread() on it. However, this will result in each thread executing a bit longer after the initial exception is caught. Is there a way to IMMEDIATELY cause every thread to suspend?
Thanks.
Upvotes: 1
Views: 705
Reputation: 1328
Did you try to use PostMessage() to GUI thread from the worker thread which was caught exception?
Brief step as proposed:
1) GUI thread spawn few worker threads
2) worker thread PostMessage() once caught exception
3) GUI thread receive message
4) GUI thread instruct remaining worker thread to suspend
Note: define your own message
By this way, you will still see some delay before suspending your worker threads.
Alternative way is to use Synchronization Object like event handle among worker threads.
Upvotes: 2