2

Possible Duplicate:
How might I schedule a C# Windows Service to perform a task daily?

I am creating a C# Windows Service, but I didn't figure out the best way to make timer fire a method daily at a specific time specified in App.Config file (e.g. daily at 6:00AM, my method is executed).

How do you do it?

Thanks

Community
  • 1
  • 1
Victor Rodrigues
  • 11,353
  • 23
  • 75
  • 107

2 Answers2

4

This code should do it:

Trigger tg = new DailyTrigger();
ScheduledTasks st = new ScheduledTasks();
Task t = st.OpenTask("foo");
t.Triggers.Add(tg);
t.Save();
aleemb
  • 31,265
  • 19
  • 98
  • 114
3

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.

ChrisF
  • 134,786
  • 31
  • 255
  • 325