Creating Scheduled Tasks

后端 未结 2 1826
半阙折子戏
半阙折子戏 2020-11-22 07:41

I am working on a C# WPF project. I need to allow the user to create and add a scheduled task to the Windows Task Scheduler.

How could I go about doing this and wha

2条回答
  •  感动是毒
    2020-11-22 07:55

    This works for me https://www.nuget.org/packages/ASquare.WindowsTaskScheduler/

    It is nicely designed Fluent API.

    //This will create Daily trigger to run every 10 minutes for a duration of 18 hours
    SchedulerResponse response = WindowTaskScheduler
        .Configure()
        .CreateTask("TaskName", "C:\\Test.bat")
        .RunDaily()
        .RunEveryXMinutes(10)
        .RunDurationFor(new TimeSpan(18, 0, 0))
        .SetStartDate(new DateTime(2015, 8, 8))
        .SetStartTime(new TimeSpan(8, 0, 0))
        .Execute();
    

提交回复
热议问题