Alex Moreno
Alex Moreno

Reputation: 138

Is it wise to use timer(s) with a windows service?

I have a console service I'm currently testing. I was planning on using a timer for it to last all day, with an interval check every 30 seconds, however, it looks like alot of people don't like using timer's with a service in that fashion. Is It wise to use a timer? or is their a better method to approach it?

Upvotes: 1

Views: 120

Answers (2)

Gary Walker
Gary Walker

Reputation: 9134

I suspect they are trying to get you to do it using a thread based method this way, which is arguably superior as the wait method is designed to awake correctly in response the the service interface.

If you need to launch very frequently the service approach is better than a scheduled task.

Upvotes: 1

Ben Voigt
Ben Voigt

Reputation: 283684

It's fine to have timers inside a service.

The question you should be asking yourself is whether you need your own service, or can just leverage a service that's already running timers (Task Scheduler). Or perhaps you should instead be responding to a user action.

Upvotes: 3

Related Questions