Scheduling within a windows service

  • Thread starter Thread starter Simon Harvey
  • Start date Start date
S

Simon Harvey

Hi all,

Can anyone point me in the direction of how to have a .net developed
service wake up every sof often to perform a task.

I need to make a service that will wake up every 15 mins to check a
database.

Is there some sort of event/notification API in .net that I can use?

I'm guessing this is a fairly typical requirement

Many thanks for your help

Simon
 
yes i think timers are the way you want to go. However spend some time
and research them a little. Some are better in certain circumstances
then others. If I remembered which was which I'd tell ya, but it was 2
years ago...
 
yes i think timers are the way you want to go. However spend some time
and research them a little. Some are better in certain circumstances
then others. If I remembered which was which I'd tell ya, but it was 2
years ago...

I couldn't get a timer to work in a service. I put a worker thread in
ran in a loop sleeping for the requisite interval and that worked
fine.
 
Imortant:
use System.Timers.Timer
not System.Windows.Forms.Timer
It caught me out

HTH
 
I couldn't get a timer to work in a service. I put a worker thread in
ran in a loop sleeping for the requisite interval and that worked
fine.
Probably Stuart Irving's comment would have solved my problem.
 
Hi Guys,

Thanks for all your comments.

I did think about using timers initially, but I was concerned that they
worked by constantly polling thereby being inefficient.

Is it definately the case that using a timer 24/7 wont be overly
burdensome? I just thought there might be some other way that was more
efficient?

I could quite believe that there isnt - I just really wanted to make
sure before I do anything

Many thanks
Simon
 
Hi Guys,

Thanks for all your comments.

I did think about using timers initially, but I was concerned that they
worked by constantly polling thereby being inefficient.

Is it definately the case that using a timer 24/7 wont be overly
burdensome? I just thought there might be some other way that was more
efficient?

I could quite believe that there isnt - I just really wanted to make
sure before I do anything

Many thanks
Simon

Neither the timer nor alternative of putting a worker thread into a
sleep loop uses any significant system resources. Neither one uses
CPU time between wake-ups or timeouts. There are two questions. One
is elegance of design and the timer is the proper way to go. The
second is how best to get the job done simply and quickly and my
worker thread did that for me faster than trying to figure out how to
make a timer function properly inside a service.
 
Stuart said:
Imortant:
use System.Timers.Timer
not System.Windows.Forms.Timer
It caught me out

No, use the System.Threading.Timers. I think these are specifically for
services.
 
Timers work just the same in a service or in a desktop application.
They are really simple, as you simply add your coded in the timer.tick or
timer.elapsed event
 
Back
Top