gpt4 book ai didi

c# - 在 Windows 任务计划程序中每天安排一个任务,周日除外

转载 作者:太空宇宙 更新时间:2023-11-03 10:52:04 26 4
gpt4 key购买 nike

为了在 Windows 任务计划程序中每周(每周一次)安排任务,我使用了来自 codeplex 的以下代码:

            TaskDefinition td = ts.NewTask();
DateTime t = ts.RootFolder.Tasks["Test"].LastRunTime;
td.RegistrationInfo.Description = "Does something";

td.Triggers.Add(new TimeTrigger(DateTime.Now + TimeSpan.FromSeconds(10)));
//td.StartBoundary = DateTime.Today + TimeSpan.FromHours(23);

td.Triggers.Add(new WeeklyTrigger
{
StartBoundary = DateTime.Today + TimeSpan.FromHours(2),
DaysOfWeek = DaysOfTheWeek.Friday
});


// Create an action that will launch Notepad whenever the trigger fires
td.Actions.Add(new ExecAction("D:\\Tasks\\obj\\x86\\Debug\\Tasks.exe", "SPU", null));

// Register the task in the root folder
ts.RootFolder.RegisterTaskDefinition(@"Test", td);

如何安排每周执行 6 天(不包括星期日)的任务?

最佳答案

我还没有尝试过,但是 DaysOfTheWeek 标有 Flags 属性,因此您应该能够像这样指定多天:

DaysOfWeek = DaysOfTheWeek.Monday | DaysOfTheWeek.Tuesday | DaysOfTheWeek.Wednesday
| DaysOfTheWeek.Thursday | DaysOfTheWeek.Friday | DaysOfTheWeek.Saturday

关于c# - 在 Windows 任务计划程序中每天安排一个任务,周日除外,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/21090794/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com