Schedule a piece of code

  • Thread starter Thread starter Guest
  • Start date Start date
G

Guest

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
 
Generally, Service should be, in my opinion, given preference over Scheduled
Tasks.

However, Schedules Tasks can also come handy if the service has nothing else
to do. Running a service for long without doing anything useful is eating
memory uselessly. At the same time, Scheduled tasks do not start if no user
is logged in.

Create a simple executable application (Console or WinForms - anything will
do). If you need any parameters to be passed, you can append them.
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

You'll need to use a timer control (System.Threading.Timer)
2) Not sure what type of app to create so that I can run it from scheduled
task without anyone logged on to machine.

No. If no user is logged in, the scheduled task cannot run.

--
Happy Hacking,
Gaurav Vaish
http://www.mastergaurav.org
http://www.edujini.in
-------------------
 
However, Schedules Tasks can also come handy if the service has nothing else
to do. Running a service for long without doing anything useful is eating
memory uselessly. At the same time, Scheduled tasks do not start if no user
is logged in.

This is incorrect. I run many scheduled tasks without any user logged in.

I have gone with the scheduled task option and it is working perfectly well
 
This is incorrect. I run many scheduled tasks without any user logged in.
I have gone with the scheduled task option and it is working perfectly
well

Hmm... then let me check up my machine.
Coz, I had a problem running a scheduled task...

May be because the Scheduled Task has a UI to display... can that be an
issue?

On the personal side... I always prefer service over scheduled tasks. More
so because the standard settings of Windows keeps all scheduled tasks as
"Shared" :(

--
Happy Hacking,
Gaurav Vaish
http://www.mastergaurav.org
http://www.edujini.in
-------------------
 
Back
Top