Hi Woo,
Windows Task Manager is able to detect this.
It uses API call SendMessageTimeout. The call sends a message to the
app, then waits up to the specified timeout period for the message to
be processed. If the message was never processed, it means the app is
likely hung.
Of course, the application might just be *busy* and not paying
attention at the moment. So you must choose an appropriately long
timeout.
If you happen to be writing the app that will be monitored, you can
ensure that it will always respond to these messages in a timely
fashion by either:
1) Periodically calling DoEvents in any code that might take a while
to execute.
2) Making sure such code is processed in a separate thread than the
one that controls the UI, and therefore the message handler.
Check out this article from MS. The title is incorrect (!), but it
really does deal with your question, and gives virtually all the code
you need for your monitoring program:
http://support.microsoft.com/kb/304990/