How to schedule a C# Windows Service to run a method daily?

26,955

Solution 1

This code should do it:

Trigger tg = new DailyTrigger();
ScheduledTasks st = new ScheduledTasks();
Task t = st.OpenTask("foo");
t.Triggers.Add(tg);
t.Save();

Solution 2

Create a scheduled task. It's by far the easiest way. If you've got enough access to install a service you should have enough access to set up a scheduled task.

Share:
26,955
Victor Rodrigues
Author by

Victor Rodrigues

Brazilian software developer, doing lots of Ruby code :D

Updated on May 29, 2020

Comments