简体   繁体   English

Windows TaskScheduler DailyTrigger运行的持续时间为

[英]Windows TaskScheduler DailyTrigger run for a duration of

I'm creating a trigger for a task in Windows using Microsoft.Win32.TaskScheduler.DailyTrigger to run daily at 8am. 我正在使用Microsoft.Win32.TaskScheduler.DailyTrigger为Windows中的任务创建触发器,以便每天早上8点运行。 That task repeats every hour but I want it to stop after 10 hours until it fires up again the next day. 这项任务每小时重复一次,但我希望它在10小时后停止,直到第二天再次启动。

In the Windows task scheduler application, under trigger you have something like "Repeat task every 1 hour for a duration of 10 hours". 在Windows任务计划程序应用程序中,在触发器下,您可以使用“每1小时重复一次任务,持续10小时”。

The repeat task every hour I can do, but I can't find a way to do the "for a duration of". 我每小时都可以做一次重复任务,但我找不到办法做“持续时间”。 This is the code I have to set up the trigger so far, startTime is a DateTime set to 8am today. 这是我到目前为止设置触发器的代码,startTime是今天设置为8am的DateTime。

var dailyTrigger = new DailyTrigger();
dailyTrigger.Repetition.Interval = TimeSpan.FromHours(1);
dailyTrigger.StartBoundary = startTime;
dailyTrigger.ExecutionTimeLimit = TimeSpan.FromMinutes(59);

I could do it with multiple triggers, but I was thinking if the application interface allows it there probably is a way to do it in code. 我可以用多个触发器来做,但我在想是否应用程序接口允许它可能有一种方法在代码中执行它。

EDIT: I noticed below is a different class, and the OP probably downloaded a library from Codeplex . 编辑:我注意到下面是一个不同的类,OP可能从Codeplex下载了一个库 The below still applies, it's just Repetition.Interval and Repetition.Duration . 以下仍然适用,它只是Repetition.IntervalRepetition.Duration

// Set the time in between each repetition of the task after it starts to 30 minutes.
tt.Repetition.Interval = TimeSpan.FromMinutes(60); // Default is TimeSpan.Zero (or never)
// Set the time the task will repeat to 1 day.
tt.Repetition.Duration = TimeSpan.FromDays(1); // Default is TimeSpan.Zero (or never)

https://msdn.microsoft.com/en-us/library/office/microsoft.office.excel.server.addins.computecluster.taskscheduler.trigger.intervalminutes(v=office.12).aspx https://msdn.microsoft.com/en-us/library/office/microsoft.office.excel.server.addins.computecluster.taskscheduler.trigger.intervalminutes(v=office.12).aspx

IntervalMinutes IntervalMinutes

Gets or sets the number of minutes between executions for a task that is to run repeatedly. 获取或设置要重复运行的任务的执行之间的分钟数。

[...] [...]

The task continues to run repeatedly until the interval specified in the DurationMinutes property expires. 任务继续重复运行,直到DurationMinutes属性中指定的时间间隔到期。 The IntervalMinutes value is counted from the start of the previous execution. IntervalMinutes值从上一次执行的开始计算。 The

IntervalMinutes value must be less than the DurationMinutes value. IntervalMinutes值必须小于DurationMinutes值。

https://msdn.microsoft.com/en-us/library/office/microsoft.office.excel.server.addins.computecluster.taskscheduler.trigger.durationminutes(v=office.12).aspx https://msdn.microsoft.com/en-us/library/office/microsoft.office.excel.server.addins.computecluster.taskscheduler.trigger.durationminutes(v=office.12).aspx

DurationMinutes DurationMinutes

Gets or sets the number of minutes that the trigger remains active after the trigger fires. 获取或设置触发器触发后触发器保持活动状态的分钟数。

[...] [...]

This property is used in conjunction with the IntervalMinutes property to run a task repeatedly for a period of time. 此属性与IntervalMinutes属性一起使用,以在一段时间内重复运行任务。 For example, to start a task at 8:00 AM and repeatedly restart it until 5:00 PM, the DurationMinutes value would be 540 minutes (9 hours). 例如,要在上午8:00启动任务并反复重新启动它直到下午5:00,则DurationMinutes值将为540分钟(9小时)。

The DurationMinutes value can also be used to terminate a running task after the DurationMinutes property for the task expires. 在任务的DurationMinutes属性到期后,DurationMinutes值还可用于终止正在运行的任务。

You use the KillAtDurationEnd property to specify that the task is terminated after its DurationMinutes expires. 您使用KillAtDurationEnd属性指定任务在其DurationMinutes到期后终止。 The value of DurationMinutes must be greater than or equal to the IntervalMinutes setting. DurationMinutes的值必须大于或等于IntervalMinutes设置。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 TaskScheduler总是在同一个线程上运行 - TaskScheduler to always run on the same thread 如何使用等待在自定义 TaskScheduler 上运行任务? - How to run a Task on a custom TaskScheduler using await? 使TaskScheduler同步并在主线程中运行 - Make the TaskScheduler synchronously and run in the main thread 如何在C#中使用TaskScheduler设置“仅在登录时运行”和“运行为”? - How to set “run only if logged in” and “run as” with TaskScheduler in C#? Windows 7使用C#TaskScheduler库创建的.job文件是否过时? - Are the .job files created using the C# TaskScheduler library obsolete for Windows 7? 为 Windows Server 2016 使用 Microsoft.Win32.TaskScheduler DLL - Using the Microsoft.Win32.TaskScheduler DLL For Windows Server 2016 Windows双击持续时间 - Windows doubleclick duration 后台任务和持续时间(Windows Phone 7) - Background task and duration (Windows Phone 7) Task.ContinueWith(...,TaskScheduler.FromCurrentSynchronizationContext())在UI线程上运行的任何场景? - Any scenario where Task.ContinueWith(…, TaskScheduler.FromCurrentSynchronizationContext()) would *not* run on the UI thread? 更改Windows Toast C#的持续时间 - Change the duration of an Windows Toast c#
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM