Link to home
Start Free TrialLog in
Avatar of azcalv408
azcalv408

asked on

vb check for program not responding (hangs)

Hi,
     I have a vb program that runs by itself for a long time and I want error handling to send a msgbox if the program hangs. Is there an error handling scheme that detects if a program doesn't respond for a long time ? thanks!
Avatar of bastibartel
bastibartel

Hi there,

You cannot issue an error from a hanging program.
Neither can a program check if it is hanging.

You could check from another program, if the first program still responds, though.

Cheers,
Sebastian
Avatar of Rob_Jeffrey
I believe bastibartel is right.  I don't think there is any way to generate an event if a program hangs.

The best way I can think of is like bastibartel said - have another program check to see if the first is still responding.

The second program can send a windows message every x minutes (or seconds) and expect a response back.  If no response is received - then display the message box.  The second program can even be written to end the first program and start it again.

This is how watchdog devices work.  A watchdog card is simply a device that has a timer and a relay.  Once the timer is started it then counts down - if it reaches zero it will reset the computer.  Software needs to set the timer every few minutes before the timer expires - if the computer locks up then the software won't be able to reset the timer and the computer will eventually be reset by the card.
Avatar of azcalv408

ASKER

Hi,
Correct me if I'm wrong, is this the send message function you were talking about above?

Private Declare Function SendMessageTimeout _
      Lib "user32" Alias "SendMessageTimeoutA" _
      (ByVal hwnd As Long, _
      ByVal msg As Long, _
      ByVal wParam As Long, _
      ByVal lParam As Long, _
      ByVal fuFlags As Long, _
      ByVal uTimeout As Long, _
      lpdwResult As Long) As Long
 
ASKER CERTIFIED SOLUTION
Avatar of Rob_Jeffrey
Rob_Jeffrey

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
If you ask me...
It is better to create new exe file then this application will determine if a certain program hangs...

found this link...
https://www.experts-exchange.com/questions/20539441/Running-an-Aplication-on-a-remote-computer.html

here is the accepted answer...

1). start a Vb project.
2). place a timer control on form.
3). set timer interval as your choice.
4). in timer event of timer control do the followigns:-
    a). use FindWindow Api to find the application window you want to check
    b). if api return you some window handle mean a positive value then it means that application you are looking for is running. but if it returns 0 then it means application is stopped.
    c). if you find that application is stopped use Shell statement to run the application you want to restart.


hope it helps...
cheers...
JackOfPH, won't that work only if the program actually exits?

The FindWindow API will still return the hwnd of the program's window if the program locked up - or has stopped all processing if a modal window is open.

The only way to know if a program hasn't locked up is to get a response from it.  Does FindWindow require a response from the program, or does it merely return the window's handle?
in that case your solution might work.. sorry... my mistake :) thanks!