VAAA
VAAA

Reputation: 15049

Best way to run process on certain hours

Hi I have a Windows Service in C#. Inside my windows service I need to run a process on determined hours hh:mm:ss.

For example I need to run the process at:

(These hours can change, so Im thinking in storing those in a XML file)

Right now I used to have a timer with interval of 6 hours, so every 6 hours the process was executed. Now the requirement is other. I need to run on a specific schedule.

Also I was requested to add an option that the windows service can run the process on every X hours and Y minutes.

Any clue how can I code that?

Thanks.

Upvotes: 2

Views: 202

Answers (2)

Reza Aghaei
Reza Aghaei

Reputation: 125292

Another good way could be using Quartz

Quartz.NET
Quartz.NET is a full-featured, open source job scheduling system that can be used from smallest apps to large scale enterprise systems.

Job Scheduling in Quartz
Jobs are scheduled to run when a given Trigger occurs. Triggers can be created with nearly any combination of the following directives:

  • at a certain time of day (to the millisecond)
  • on certain days of the week
  • on certain days of the month
  • on certain days of the year
  • not on certain days listed within a registered Calendar (such as business holidays)
  • repeated a specific number of times
  • repeated until a specific time/date
  • repeated indefinitely
  • repeated with a delay interval

Upvotes: 2

Colin Grealy
Colin Grealy

Reputation: 615

Why reinvent the wheel? Just use Windows Task Scheduler to run your process.

If you want to setup the task scheduler from your code, you can use the Managed Task Scheduler Wrapper

Upvotes: 1

Related Questions