DelphiFAQ Home Search:

Recognize frozen applications (Watchdog)

 

commentsThis article has not been rated yet. After reading, feel free to leave comments and rate it.

Question:

I am developing a sort of watchdog and I need to programatically check from an application, if another application is not responding. How can I do this?


Answer:

Try by sending a message with SendMessageTimeOut. If the another application is not responding, there is a timout. The example below searches for application 'MyApplication' in the main window's caption bar and gives it 3 seconds to respond to a message.

function AppFrozen(H: HWND) : Boolean;
var
  dwResult: DWord;
const
  timeout = 3000; // ms
begin
  AppFrozen := SendMessageTimeout(H, WM_NULL, 0, 0, 
                                  SMTO_ABORTIFHUNG or SMTO_BLOCK, 
                                  timeout, dwResult) <> 0
end;


var
  H: HWND;

begin
  // enumerate top level windows or search for an
  // application that you are monitoring
  H := FindWindow(nil, 'MyApplication');
  if H<>0 then
    if AppFrozen(H) then
      ShowMessage('MyApplication is Frozen!')
end.
You don't like the formatting? Check out SourceCoder then!

Comments:

 

 

NEW: Optional: Register   Login
Email address (not necessary):

Rate as
Hide my email when showing my comment.
Please notify me once a day about new comments on this topic.
Please provide a valid email address if you select this option, or post under a registered account.
 

Show city and country
Show country only
Hide my location
You can mark text as 'quoted' by putting [quote] .. [/quote] around it.
Please type in the code:

Please do not post inappropriate pictures. Inappropriate pictures include pictures of minors and nudity.
The owner of this web site reserves the right to delete such material.

photo Add a picture: