Go Premium for a chance to win a PS4. Enter to Win

x
?
Solved

vb check for program not responding (hangs)

Posted on 2006-07-06
8
Medium Priority
?
497 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
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
Concerto Cloud for Software Providers & ISVs

Can Concerto Cloud Services help you focus on evolving your application offerings, while delivering the best cloud experience to your customers? From DevOps to revenue models and customer support, the answer is yes!

Learn how Concerto can help you.

 
LVL 26

Expert Comment

by:EDDYKT
ID: 17056369
0
 
LVL 9

Accepted Solution

by:
Rob_Jeffrey earned 440 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

Industry Leaders: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

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

The debugging module of the VB 6 IDE can be accessed by way of the Debug menu item. That menu item can normally be found in the IDE's main menu line as shown in this picture.   There is also a companion Debug Toolbar that looks like the followin…
I was working on a PowerPoint add-in the other day and a client asked me "can you implement a feature which processes a chart when it's pasted into a slide from another deck?". It got me wondering how to hook into built-in ribbon events in Office.
Show developers how to use a criteria form to limit the data that appears on an Access report. It is a common requirement that users can specify the criteria for a report at runtime. The easiest way to accomplish this is using a criteria form that a…
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

886 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