Celebrate National IT Professionals Day with 3 months of free Premium Membership. Use Code ITDAY17

x
?
Solved

vb check for program not responding (hangs)

Posted on 2006-07-06
8
Medium Priority
?
489 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
Independent Software Vendors: 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!

 
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

Free Tool: Subnet Calculator

The subnet calculator helps you design networks by taking an IP address and network mask and returning information such as network, broadcast address, and host range.

One of a set of tools we're offering 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

Introduction While answering a recent question (http://www.experts-exchange.com/Q_27402310.html) in the VB classic zone, I wrote some VB code in the (Office) VBA environment, rather than fire up my older PC.  I didn't post completely correct code o…
Background What I'm presenting in this article is the result of 2 conditions in my work area: We have a SQL Server production environment but no development or test environment; andWe have an MS Access front end using tables in SQL Server but we a…
Get people started with the process of using Access VBA to control Outlook using automation, Microsoft Access can control other applications. An example is the ability to programmatically talk to Microsoft Outlook. Using automation, an Access applic…
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…
Suggested Courses

730 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