1

I am working on a window service and I have to schedule it. Schedule is set to any three days of a week and four times a day. At any time when one starts service, It must pick the next execution time.

This next execution time can be in the same day or next scheduled day(may be with the gap of a day or two).

Kiquenet
  • 14,494
  • 35
  • 148
  • 243
Lali
  • 2,816
  • 4
  • 30
  • 47
  • 1
    It is always nice to see what you have tried. – Brett Jan 19 '13 at 21:35
  • 1
    Why do you want to start it manually? A windows-service is something that runs continuously in background and does what it's supposed to do when the time has come. As alternative you can use a scheduled task which you can also fine-tune. – Tim Schmelter Jan 19 '13 at 21:35
  • I have to start it first time. At any time when I will start it, It must pick the next execution time. – Lali Jan 19 '13 at 21:41
  • So, could you include an execution schedule pattern? – Alex Filipovici Jan 19 '13 at 21:52
  • Execution schedule pattern? I simply have twelve entries in db. Like 1-----Tuseday-----8am------
    2-----Tuseday-----2pm------
    3-----Tuseday-----6pm------
    4-----Tuseday-----11pm-----
    5-----Friday------8am------
    ----And so on I have to pick next entry/record from the unordered collection.
    – Lali Jan 19 '13 at 22:08
  • Why not just use the Windows scheduler and create the required schedule triggers? – Lloyd Jan 19 '13 at 22:18
  • 1
    Don't provide additional information in comments, please. Edit your question and add it there, so people can see it when reading your question without having to wade through comments to find it. It improves your chances of getting an answer if all of the information is in the question itself. Thanks. – Ken White Jan 19 '13 at 22:27

1 Answers1

1

Take a look at Task Scheduler Managed Library (Codeplex). I believe it is maintained by Microsoft themselves.

Once you add the DLL reference to Microsoft.Win32.TaskScheduler, you can use it really easily like so:

var taskService = new TaskService();
var task = taskService.NewTask();

task.Triggers.Add(new WeeklyTrigger(DaysOfTheWeek.Friday, 1));
task.Actions.Add(new ExecAction("YourProgram.exe", null, null));

task.RootFolder.RegisterTaskDefinition("YourTaskName", task);

That will register a task that runs every Friday, executing YourProgram.exe.

Erik
  • 12,730
  • 5
  • 36
  • 42