2

I'm trying to create tasks with an indefinite duration. On Windows Server 2008, if I don't specify the duration, then the duration is assumed infinite. However, on Windows Server 2003 a duration must be specified (and be equal or greater than the interval). Currently, I am just setting the task to have a duration of a year if it is meant to repeat a long time.

Is there a way to specify an indefinite duration on Windows Server 2003?

if (m_TimeInterval.m_Expire.Year < 2099) //xp and win7 max year is 2099
    tTrigger.Repetition.Duration = m_TimeInterval.getDuration();
else if (!newVer) tTrigger.Repetition.Duration = m_TimeInterval.getInterval().Add(TimeSpan.FromDays(365));
tTrigger.Repetition.Interval = m_TimeInterval.getInterval();
tTrigger.Repetition.StopAtDurationEnd = true;

Notes:

  • I am using the Task Scheduler API to add these task definitions.
  • Interval and Duration are set by use of TimeSpans.
  • newVer is false since I am working with Task Scheduler 1.1 and not 1.2 or higher
  • tTrigger is of type TimeTrigger
PAULDAWG
  • 780
  • 5
  • 21
  • What about creating a separate Schedule Task whose sole purpose is to stop and restart the task you want to have an indefinite duration, effectively resetting the duration? – Darth Continent Jun 08 '12 at 21:08
  • That is a possible work-around, thanks. Although, stopping and starting the task would not update the original timespan of a year defined, so it would have to delete and recreate the tasks. – PAULDAWG Jun 11 '12 at 15:57

3 Answers3

1

I ended up using 1-1-2099 as 'indefinite'

PAULDAWG
  • 780
  • 5
  • 21
1

You also can use TimeSpan.Zero which makes the task infinite.

Heres a short code snippet to demonstrate how to use it on a Trigger :

Trigger triggerTask = Trigger.CreateTrigger(TaskTriggerType.Time);
triggerTask.StartBoundary = DateTime.Now.AddMinutes(3);
triggerTask.SetRepetition(new TimeSpan(0, 3, 0, 0, 0), TimeSpan.Zero);
Alex Pan
  • 4,341
  • 8
  • 34
  • 45
CoreX1337
  • 11
  • 1
0

Can you use Duration.Forever.TimeSpan?

John Watts
  • 8,717
  • 1
  • 31
  • 35
  • The description is right on the money, but it looks like that's a WPF base element class. Services are essentially console applications. – PAULDAWG Jun 11 '12 at 15:53