Solved

vb check for program not responding (hangs)

Posted on 2006-07-06
8
471 Views
Last Modified: 2008-01-09
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!
0
Comment
Question by:azcalv408
8 Comments
 
LVL 5

Expert Comment

by:bastibartel
Comment Utility
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
0
 
LVL 9

Expert Comment

by:Rob_Jeffrey
Comment Utility
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.
0
 

Author Comment

by:azcalv408
Comment Utility
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
 
0
 
LVL 26

Expert Comment

by:EDDYKT
Comment Utility
0
Enabling OSINT in Activity Based Intelligence

Activity based intelligence (ABI) requires access to all available sources of data. Recorded Future allows analysts to observe structured data on the open, deep, and dark web.

 
LVL 9

Accepted Solution

by:
Rob_Jeffrey earned 110 total points
Comment Utility
Yes you can use SendMessage but since we need to know if the message is responded to we would use

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, _
    pdwResult As Long) As Long

The link EDDYKT provided above is an excellent working example for you to use.
0
 
LVL 15

Expert Comment

by:JackOfPH
Comment Utility
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...
http://www.experts-exchange.com/Programming/Programming_Languages/Visual_Basic/Q_20539441.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...
0
 
LVL 9

Expert Comment

by:Rob_Jeffrey
Comment Utility
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?
0
 
LVL 15

Expert Comment

by:JackOfPH
Comment Utility
in that case your solution might work.. sorry... my mistake :) thanks!
0

Featured Post

Find Ransomware Secrets With All-Source Analysis

Ransomware has become a major concern for organizations; its prevalence has grown due to past successes achieved by threat actors. While each ransomware variant is different, we’ve seen some common tactics and trends used among the authors of the malware.

Join & Write a Comment

There are many ways to remove duplicate entries in an SQL or Access database. Most make you temporarily insert an ID field, make a temp table and copy data back and forth, and/or are slow. Here is an easy way in VB6 using ADO to remove duplicate row…
When trying to find the cause of a problem in VBA or VB6 it's often valuable to know what procedures were executed prior to the error. You can use the Call Stack for that but it is often inadequate because it may show procedures you aren't intereste…
As developers, we are not limited to the functions provided by the VBA language. In addition, we can call the functions that are part of the Windows operating system. These functions are part of the Windows API (Application Programming Interface). U…
Get people started with the utilization of class modules. Class modules can be a powerful tool in Microsoft Access. They allow you to create self-contained objects that encapsulate functionality. They can easily hide the complexity of a process from…

763 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

11 Experts available now in Live!

Get 1:1 Help Now