Mega Code Archive

 
Categories / Delphi / Examples
 

Check if an application is hung

Title: Check if an application is hung Question: 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_NULL, 0, 0, SMTO_ABORTIFHUNG Or SMTO_BLOCK, timeOut, dwResult) 0; end; Enjoy.