Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Shaun E on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

run as service

Status
Not open for further replies.

MrDontKnowNothing

Programmer
Jun 26, 2003
94
DE
hello everyone,

i do have a litle *.prg, wich i want to run as a service in windows. therefore i need some mechanismn, that controls that service, so that it runs only once a day.

my idea: when it runs as *.exe, i need to check the system clock periodically. does anybody know how to do that? shall i use sleep within a loop?

e.g.:

DECLARE Sleep IN Win32API INTEGER

do while (.t.)
if time() == 'hh:mm:ss'
? 'hello'
enddo
sleep(30000)
enddo

gracias!

alex
 
you can also use the timer control (the control that looks like a watch of some kind) which can be found on your controls toolbar. from there, you can set the timer's interval property (interval between event firing) and the timer event (contains the code you want to execute between intervals).

hope this helps.

kilroy [trooper]
 
MrDontKnowNothing

Why not run it as a scheduled task, using Windows Task scheduler. We use 7 or 8 of these in the Window Task scheduler that run as overnite services, to update, pack and re-index databases.

Mike Gagnon

If you want to get the best response to a question, please check out FAQ184-2483 first.
 
i can't use the timer control since there is no gui in my prog.

as far as i know, somebody need to be logged in, in order to run the services in the task scheduler. but i need something, wich runs independent of any user.

cheers alex
 
MrDontKnowNothing,

I'm assuming from what you have said that you already know how to create your service (plenty of good threads on it in this forum) and your only problem is to make a timer object in code. As jimoo has pointed out the timer object is not dependent on any kind of a user interface. Cut-N-Paste the code below into a prg file and run it from within VFP.

Code:
PUBLIC oTimer
oTimer = CREATEOBJECT("clsTimer")
oTimer.interval = 4000

DEFINE CLASS clsTimer as Timer

PROCEDURE timer
	IF MESSAGEBOX("Timer has just fired!  Continue running?",36,"TIMER MESSAGE") != 6
		RELEASE this
	ENDIF		
ENDPROC

ENDDEFINE

Slighthaze = NULL

[ul][li]FAQ184-2483
An excellent guide to getting a fast and accurate response to your questions in this forum.[/li][/ul]
 
I'll throw in my two cents and say it's better to let
Windows handle the timing of the application's run time.

If you use a timer; which I do often :); you'll be eating
up an unnecessary amount of system resources just waiting
for the hour to arrive.

Let Windows handle the time-to-run, let your app get
awakened, do its job, and exit.

Your system will be happier.

Darrell
 
hi darrelblackhawk,

but how can i let windows handle that, since i cannot use the windows scheduler, cause it only works, as far as i know, as long as some user is logged into the system, wich is not the case.

mfg alex
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top