How should I schedule a piece of code to run?

  • Thread starter Thread starter Terry Holland
  • Start date Start date
T

Terry Holland

Im looking for some advice on the best direction to go in.

I have the need for a function to be run at a set time each night. This
function will be run on a machine that will have no-one logged on at the
time
this function will run. The alternatives that Im considering are

1) Create a windows service. Have a timer control in this service and set
the interval to 24 hour and have the function being called on the
Timer1_Tick
event

or

2) Create a app (which type?) that will be executed using a Scheduled Task

What im not sure about is

1) Ive never created a servioce before so Im not sure if I can schedule this
to run atspecific time of day or whether I shouyld use a timer control

2) Not sure what type of app to create so that I can run it from scheduled
task without anyone logged on to machine.

Could someone please advise. Some example code would be helpfull.

Terry Holland
 
You surely can set up a service to do this, but a timer is not your best
option. Any glitches in the system will cause it to reset and fire at the
wrong time. You can poll time, of course, but watch that you do not put
weight on your system. Scheduled jobs are a better option in many ways,
although the windows scheduler can be a pain if you have lots of these jobs.
The good news is you can switch to another scheduler in the future, if you
go this route.

--
Gregory A. Beamer

*************************************************
Think Outside the Box!
*************************************************
 
Use the Windows Scheduler. I have a server with over a dozen jobs scheduled
this way and don't have any problems with any of them. Just remember, that
any unattended application requires a "try...catch...end try" handler around
the entire application nor can it expect any user input.

Mike Ober.
 
Thanks


Schedular it is then :-)





Michael D. Ober said:
Use the Windows Scheduler. I have a server with over a dozen jobs scheduled
this way and don't have any problems with any of them. Just remember, that
any unattended application requires a "try...catch...end try" handler around
the entire application nor can it expect any user input.

Mike Ober.
 
Use the Windows Scheduler. I have a server with over a dozen jobs
scheduled this way and don't have any problems with any of them. Just
remember, that any unattended application requires a
"try...catch...end try" handler around the entire application nor can
it expect any user input.

Don't forget about logging and notification on failures. It's great to have
an application that gracefully closes, but you might be in trouble if you
didn't realize that the scheduled job that processes the daily payroll failed
for the last 2 weeks.

Jim Wooley
http://devauthority.com/blogs/jwooley/default.aspx
 
Back
Top