dahall / TaskScheduler

Provides a .NET wrapper for the Windows Task Scheduler. It aggregates the multiple versions, provides an editor and allows for localization.
MIT License
1.21k stars 191 forks source link

Add an Example for Trigger.Repetition Property #863

Closed rakshitharam closed 3 years ago

rakshitharam commented 3 years ago

Please add an example for Trigger.Repetition Property.

I want to set up two scheduled tasks:

  1. Set a task to run at 11 pm every night
  2. Set the task to run per day 30 minutes after the first scheduled task is set to run. Repeat this task every 30 minutes for 2 hours.

Please give an example to show how this repetition can be set up

dahall commented 3 years ago
// Instantiate a daily trigger that runs every day
var dt = new DailyTrigger(1);
// Starting today at 11pm
dt.StartBoundary = DateTime.Today.AddHours(23);
// Set the repetition to run every 30 mins for 2 hrs without a forced stop at the 2 hr mark
dt.SetRepetition(TimeSpan.FromMinutes(30), TimeSpan.FromHours(2), false);
// Create task with trigger
TaskService.Instance.AddTask("MyTask", dt, new ExecAction("yourexehere.exe"));