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

x
?
Solved

shutting down an vb exe  when OS shuts down

Posted on 2002-07-14
9
Medium Priority
?
185 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
[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
9 Comments
 
LVL 143

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 200 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
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 4

Expert Comment

by:AlonHirsch
ID: 7153908
Hi Sabnis,

What objects would you wait for ?

Alon
0
 

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

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!

Question has a verified solution.

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

Have you ever wanted to restrict the users input in a textbox to numbers, and while doing that make sure that they can't 'cheat' by pasting in non-numeric text? Of course you can do that with code you write yourself but it's tedious and error-prone …
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…
Get people started with the process of using Access VBA to control Excel using automation, Microsoft Access can control other applications. An example is the ability to programmatically talk to Excel. Using automation, an Access application can laun…
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