Posted By: raptor3676 | Nov 9th, 2008 @ 3:42 PM
page 1 of 1
Comments: 7 | Views: 633
Hi, everyone

Currently I'm working on a long running program whose task is to log information 24x7 from several servers, and it is supposed to do some aditional logging duties at 7AM everyday. 

What's the best way to do that? I've been thinking of setting a thread to sleep for 24 hours wake up do the task and then back to sleep.  But that doesn't seems a very elegant solution.

Any idea anyone?

Thanx in advance.

BTW, I'm using C#
use the windows scheduler, make your app single instance, schedule starting when needed, pass a command line arg indicating the job to be performed?
figuerres
figuerres
???
SOunds to me like you have a case for a Windows Service.

runs automaticaly, can re-start when the server re-starts, and so on...

I have done a few of them for custom stuff like this.

basics are simple:  create a new project with the windows service template, add a service installer, set properties.

most of the time I add the "Background worker" component and use it to provide my main worker.

the service has events you use to start / stop your worker.

you can use a standard system account or a custom account, try to use a standard one with minimal privelges, best practice for security.

inside the background worker I use a while loop and a threading sleep with an interval - time span.

any other questions ??
TommyCarlier
TommyCarlier
I want my scalps!
If it only needs to perform a task once every 24 hours (or any other interval), I'd do what Ion Todirel suggests. In fact, yesterday I was watching some PowerPoint presentation from a PDC-session about Windows 7 that suggests it is much better to use the Task Scheduler for things like this than a Windows Service. A Windows Service that is loaded 24x7 takes unnecessary resources. "Play nice" Wink
As Ion and Tommy said, ues the Task Scheduler. Not only does this remove a lot of unnecessary code from your app, it also gives System Adminstrators the ability to tweak the timing of this reporting for "free". Don't reinvent wheels that don't need it.
Matthew van Eerde
Matthew van Eerde
AKA Maurits
Sounds like a job for two processes; one running as a service, and the other via Task Scheduler.  Drawback: you have to deal with the overhead of IPC.  Benefit: Task Scheduler has all kinds of ways of dealing with the "what if the consolidation takes more than 24 hours" problem, the "what if the computer was off at 7 AM" problem, etc.
yeah you could do that too and keep it simple, I wanted to suggest the use of a two threads in the same process, but it will just make things more complicated...
page 1 of 1
Comments: 7 | Views: 633
Microsoft Communities