How to programatically check if an application has hang ?

  • Thread starter Thread starter Guest
  • Start date Start date
G

Guest

Hi,

I need to write a monitoring program to check a series of application
residing in a server.

The monitoring program should be able to :-
1) Determine whether the applications it is looking at has hangup.
2) If it hangs restart the specific app.


And, how do we differentiate the app is busy or it was indeed dead?


Thank You.
mfwoo
 
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/
 
Back
Top