Windows with Delphi Windows API (94) Windows Filesystem (41) Windows Forms (69) Windows Graphics (38)
Exchange Links About this site Links to us 
|
Recognize frozen applications (Watchdog)
This 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; begin
AppFrozen := SendMessageTimeout(H, WM_NULL, 0, 0,
SMTO_ABORTIFHUNG or SMTO_BLOCK,
timeout, dwResult) <> 0
end;
var
H: HWND;
begin
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:
|