Solved

shutting down an vb exe  when OS shuts down

Posted on 2002-07-14
9
174 Views
Last Modified: 2010-05-02
Hi

i have an exe running which does some task after each 15 mins. i am using the Sleep API for the appl to sleep for the specific time period. as the exe would be running for the whole day, i would like that it should automatically close when the OS is shutting down (mostly it would be Windows NT,98 or 2000). right now it gives the "appl not responding error" while shutting down.

i actually want to know if some event is generated when the appl is closed using the task manager. i have alreaday tried the Query_Unload event.

plz help..............

thanks
0
Comment
Question by:navneetha
9 Comments
 
LVL 142

Expert Comment

by:Guy Hengel [angelIII / a3]
ID: 7153582
The Query_Unload should work, but maybe your code isn't complete or doesn't unload correctyl.
I assume you have a single form (invisble), maybe the form is not loaded at all to recieve the Query_unload event. You might check the load and unload events (by writing a small line to a debug file) to monitor these events...

CHeers
0
 
LVL 4

Accepted Solution

by:
AlonHirsch earned 50 total points
ID: 7153694
Hi,

When you use the Sleep API - your app stops responding for the entire duration it is sleeping - it does not use any CPU cycles.
To circumvent this - you need to sleep for shorter periods (maybe 10 seconds at a time) and then use a Doevents.
This will ensure that your program does checks for activity etc. every 10 seconds and then becomes dormant again.

HTH,
Alon
0
 

Expert Comment

by:Sabnis
ID: 7153872
you could use wait for WaitForMultipleObjects....
0
 
LVL 4

Expert Comment

by:AlonHirsch
ID: 7153908
Hi Sabnis,

What objects would you wait for ?

Alon
0
Better Security Awareness With Threat Intelligence

See how one of the leading financial services organizations uses Recorded Future as part of a holistic threat intelligence program to promote security awareness and proactively and efficiently identify threats.

 

Expert Comment

by:Sabnis
ID: 7154441
wait for handle of the Thread Stop Event .... the timer elapsed event ....these are the 2 events necessary...may be other events as u need
0
 

Expert Comment

by:Sabnis
ID: 7154454
wait for handle of the Thread Stop Event .... the timer elapsed event ....these are the 2 events necessary...may be other events as u need
0
 
LVL 2

Expert Comment

by:egsemsem
ID: 7154831
navneetha, if you are sure that the form is loaded, and that you use "sleep" function with small intervals. I think the problem may be in "End" statement, use this code instead:

'In you main module
Public Const ForRelease = True
Public Declare Function TerminateProcess Lib "kernel32" (ByVal ApphProcess As Long, ByVal uExitCode As Long) As Long
Public Declare Function GetCurrentProcess Lib "kernel32" () As Long

'Add this code instead of End statement
If ForRelease Then
  Dim ExitCode As Long
  TerminateProcess GetCurrentProcess, ExitCode
Else
   End
End If


The problem in this code is that it will terminate VB entirley if you run your program from VB, and so to avoid this problem, change the value of 'ForRelease' to 'False', and before you create your exe file, change it into 'True'.

Osama
 
0
 
LVL 49

Expert Comment

by:DanRollins
ID: 8012179
Hi navneetha,
It appears that you have forgotten this question. I will ask Community Support to close it unless you finalize it within 7 days. I will ask a Community Support Moderator to:

    Accept AlonHirsch's comment(s) as an answer.

navneetha, if you think your question was not answered at all or if you need help, just post a new comment here; Community Support will help you.  DO NOT accept this comment as an answer.
==========
DanRollins -- EE database cleanup volunteer
0
 
LVL 1

Expert Comment

by:Computer101
ID: 8095576
Comment from expert accepted as answer

Computer101
E-E Admin
0

Featured Post

How to run any project with ease

Manage projects of all sizes how you want. Great for personal to-do lists, project milestones, team priorities and launch plans.
- Combine task lists, docs, spreadsheets, and chat in one
- View and edit from mobile/offline
- Cut down on emails

Join & Write a Comment

This article describes some techniques which will make your VBA or Visual Basic Classic code easier to understand and maintain, whether by you, your replacement, or another Experts-Exchange expert.
If you need to start windows update installation remotely or as a scheduled task you will find this very helpful.
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…

746 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

15 Experts available now in Live!

Get 1:1 Help Now