Home All Groups Group Topic Archive Search About

How to programatically check if an application has hang ?

Author
13 Oct 2006 10:13 AM
Woo Mun Foong
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

Author
13 Oct 2006 11:26 AM
teslar91
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/
Author
14 Oct 2006 2:04 AM
Woo Mun Foong
Thanks a lot

Regards,
mfwoo

Show quoteHide quote
"tesla***@hotmail.com" wrote:

> 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/
>
>