This project has moved. For the latest updates, please go here.

Help me to set last week trigger.

May 4, 2009 at 9:03 AM
Edited May 5, 2009 at 6:02 AM

Hello,

 

I am creating a 'MonthlyDOWTrigger' trigger, which will run on every last week (on a specified day) of every month.

 

If I set,

 monthlyDowTrigger.WeeksOfMonth = WhichWeek.LastWeek

a 'System.ArgumentException' is thrown.

 

If I set,

monthlyDowTrigger.RunOnLastWeekOfMonth = True

the task gets register but it gets register with first week and last week. Ideally it should register with only last week.

 

If I set, both the properties

 monthlyDowTrigger.RunOnLastWeekOfMonth = True

 monthlyDowTrigger.WeeksOfMonth = WhichWeek.SecondWeek

the task gets register but it gets register with Second week and last week.

 

If I set

 monthlyDowTrigger.RunOnLastWeekOfMonth = True

 monthlyDowTrigger.WeeksOfMonth = WhichWeek.LastWeek

a 'System.ArgumentException' is thrown.

 

This is my code for creating task:

 

 Dim td As TaskDefinition = ts.NewTask()

 td.RegistrationInfo.Description = "Trying Own Task "

 

 // Create a  MonthlyDOWTrigger

  Dim monthlyDowTrigger As MonthlyDOWTrigger = New MonthlyDOWTrigger

   monthlyDowTrigger.StartBoundary = DateTime.Now.AddSeconds(30)

   monthlyDowTrigger.RunOnLastWeekOfMonth = True

  // monthlyDowTrigger.WeeksOfMonth = WhichWeek.LastWeek

   monthlyDowTrigger.DaysOfWeek = DaysOfTheWeek.Sunday

   monthlyDowTrigger.MonthsOfYear = MonthsOfTheYear.AllWeeks

       

   td.Triggers.Add(monthlyDowTrigger)

 

// Add an action

 

 td.Actions.Add(New ExecAction("notepad.exe", "D:\\test.log", Nothing))

 

//Register a task

ts.RootFolder.RegisterTaskDefinition("SampleTask", td, TaskCreation.Create, Nothing, Nothing, TaskLogonType.InteractiveToken, Nothing)

 

Is there any way to register the task having trigger, which will get activated only on the last week (on specified day) of the month?

Thanks.

      

Coordinator
Jul 9, 2009 at 6:11 AM
Edited Jul 9, 2009 at 6:12 AM

There is an error in the Microsoft documentation for WeeksOfMonth. It states that there is a FifthWeek (0x10) and a LastWeek (0x20). Doing some testing it appears that there should not be a FifthWeek and that LastWeek should equal 0x10. I will update the code base, but as a workaround, you can set WeeksOfMonth to FifthWeek for now.

Coordinator
Jul 9, 2009 at 6:17 AM
This discussion has been copied to a work item. Click here to go to the work item and continue the discussion.