Solved

vb check for program not responding (hangs)

Posted on 2006-07-06
8
485 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
8 Comments
 
LVL 5

Expert Comment

by:bastibartel
ID: 17055505
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
ID: 17055558
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
ID: 17055594
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
Online Training Solution

Drastically shorten your training time with WalkMe's advanced online training solution that Guides your trainees to action. Forget about retraining and skyrocket knowledge retention rates.

 
LVL 26

Expert Comment

by:EDDYKT
ID: 17056369
0
 
LVL 9

Accepted Solution

by:
Rob_Jeffrey earned 110 total points
ID: 17057799
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
ID: 17063332
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
ID: 17063445
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
ID: 17070281
in that case your solution might work.. sorry... my mistake :) thanks!
0

Featured Post

Free Tool: IP Lookup

Get more info about an IP address or domain name, such as organization, abuse contacts and geolocation.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

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…
Enums (shorthand for ‘enumerations’) are not often used by programmers but they can be quite valuable when they are.  What are they? An Enum is just a type of variable like a string or an Integer, but in this case one that you create that contains…
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…
This lesson covers basic error handling code in Microsoft Excel using VBA. This is the first lesson in a 3-part series that uses code to loop through an Excel spreadsheet in VBA and then fix errors, taking advantage of error handling code. This l…
Suggested Courses
Course of the Month6 days, 9 hours left to enroll

636 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