Click here to Skip to main content
15,885,309 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
Background: I have developed a windows service which runs once every day and does the work (every thing is just right!)

Issue: the service runs exactly at the same time (last run time) the other day.. Ex: If I start the service at 4:00 PM today so it will run again at 4:00 PM every day.

My solution till yet (but not working fine) I want it to configure it self with the StartTime and IntervalTime mentioned in the app.config file and run at that time everyday (regardless of when I have started it)

Having problems with this silly thing .. Please help in this regards with sample code. Your help is really appreciated, Thanks in advance.

For further clarification, if I have mentioned in app.config

key="StartTime" value="12:00"
key="Interval" value="86400000"


so it must run on 12:00 PM every day (as interval period is 86400000 milliseconds i.e. 1day) regardless of the time when I started it or make it live.
Posted
Updated 30-Aug-11 2:31am

1 solution

A windows service is not really meant to work like this, a service is 'constantly running' rather than interval based.

Your best bet here is just to write a standard program and have it execute under 'Scheduled Tasks' which will handle all of your issues
 
Share this answer
 
Comments
Abhinav S 30-Aug-11 8:25am    
Good comment.
iiicode 30-Aug-11 8:25am    
yeah windows service is constantly running program in the background - that what it is constantly running task every day but once.

Windows Scheduled Tasks is not software engineer solution - I would be great if we could handle it in code. what you think?

Thanks for your reply!
Dylan Morley 30-Aug-11 8:32am    
As with anything in programming, it's all about choosing the right tools to complete the job.

Windows has thoughtfully provided a scheduling system for us, why would I want to reinvent this? It's been done for me, has years of testing behind it and works well. All I've got to focus on is writing the code that runs at the interval.

If you insist on writing a program that runs as a service, you're going to have numerous issues. (and I say you're choosing the wrong tool for the job)

1) If you just want it to run and execute at a certain interval, then what is going to check the time\interval and start the service. That would need to be another program (hint: Scheduled Tasks!)

2) If you want it running all the time, then you'll need to write your own logic for testing the current time against your interval configuration - reinventing to wheel

'Windows Scheduled Tasks' certainly is a valid software engineer solution....'reuse as much as possible' :)

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900