API - sendmessages timeout

Top  Previous  Next

// Question/Problem/Abstract:

// How can I check if an application is still running or has stopped responding? 

// Answer:

// The answer is simple: SendMessageTimeout! 

// Using this API you can send a message to a window and wait for a timeout 

// before continuing; if the application responds before timeout the is still running 

// else is hung. 

// Here how to use it. 

 

function isHung(theWindow: HWnd; timeOut: Longint): Boolean; 

var 

  dwResult: DWord; 

begin 

  Result := SendMessageTimeout(theWindow, WM_NULL00, SMTO_ABORTIFHUNG or SMTO_BLOCK, timeOut, dwResult) <> 0

end;