This project has moved and is read-only. For the latest updates, please go here.

WeeklyTrigger with different times for each day

Jun 18, 2012 at 7:05 PM

Hi,

I am trying to set a new task with a weekly trigger. It should run every day, but at different times. For example Monday 8am, Tuesday 11am, Wednesday 8pm....

With Win7 i have no problems, but with WindowsXP it does'nt work right. Perhaps I made a mistake?

Here's my code

using (TaskService ts = new TaskService())
                {
                   // Retrieve the task, change the trigger and re-register it
                    Task t = ts.GetTask(strTaskName);
                    TaskDefinition td = ts.NewTask();

                    if (t == null)           // TaskDefinition neu f�llen
                    {
                        // Display version and server state
                        Version ver = ts.HighestSupportedVersion;
                        bool newVer = (ver >= new Version(1, 2));

                        // Beschreibung
                        td.RegistrationInfo.Description = strTaskBeschreibung;

                        // Login-Typ
                        if (newVer)
                            td.Principal.LogonType = TaskLogonType.S4U;
                        else
                            td.Principal.LogonType = TaskLogonType.InteractiveToken;
                    }
                    else                    // aktuelle TaskDefinition holen
                    {
                        td = t.Definition;
                    }
                    
                    // Trigger hinzuf�gen
                    td.Triggers.Clear();

                    DateTime dateNow = DateTime.Now;
                    foreach (var item in listTriggerWoche)
                    {
                        TriggerWoche triggerAktuell = (TriggerWoche)item;

                        // Startzeit
                        DateTime time = new DateTime(dateNow.Year, dateNow.Month, dateNow.Day, triggerAktuell.Stunde, triggerAktuell.Minute, 0);

                        // w�chentlichen Trigger hinzuf�gen
                        switch (triggerAktuell.Tag)
                        {
                            case 0: WeeklyTrigger wt1 = (WeeklyTrigger)td.Triggers.Add(new WeeklyTrigger { DaysOfWeek = DaysOfTheWeek.Monday, StartBoundary = time }); break;
                            case 1: WeeklyTrigger wt2 = (WeeklyTrigger)td.Triggers.Add(new WeeklyTrigger { DaysOfWeek = DaysOfTheWeek.Tuesday, StartBoundary = time }); break;
                            case 2: WeeklyTrigger wt3 = (WeeklyTrigger)td.Triggers.Add(new WeeklyTrigger { DaysOfWeek = DaysOfTheWeek.Wednesday, StartBoundary = time }); break;
                            case 3: WeeklyTrigger wt4 = (WeeklyTrigger)td.Triggers.Add(new WeeklyTrigger { DaysOfWeek = DaysOfTheWeek.Thursday, StartBoundary = time }); break;
                            case 4: WeeklyTrigger wt5 = (WeeklyTrigger)td.Triggers.Add(new WeeklyTrigger { DaysOfWeek = DaysOfTheWeek.Friday, StartBoundary = time }); break;
                            case 5: WeeklyTrigger wt6 = (WeeklyTrigger)td.Triggers.Add(new WeeklyTrigger { DaysOfWeek = DaysOfTheWeek.Saturday, StartBoundary = time }); break;
                            case 6: WeeklyTrigger wt7 = (WeeklyTrigger)td.Triggers.Add(new WeeklyTrigger { DaysOfWeek = DaysOfTheWeek.Sunday, StartBoundary = time }); break;
                        }
                    }

                    td.Actions.Clear();
                    td.Actions.Add(new ExecAction(strPfadExecuteDatei, "", null));

                    // Aufgabe (wieder) registrieren
                    ts.RootFolder.RegisterTaskDefinition(strTaskName, td);
                }

 

Now - if i try to get the days of the weekly triggers, i always get sunday?

 

using (TaskService ts = new TaskService())
                {
                    Task t = ts.GetTask(strTaskName);
                    TaskDefinition td = ts.NewTask();

                    if (t == null)           // TaskDefinition neu f�llen
                    {
                        return;
                    }
                    else                    // aktuelle TaskDefinition holen
                    {
                        td = t.Definition;
                    }

                   foreach (var item in td.Triggers)
                    {
                        Trigger trigger = (Trigger)item;
                        TaskTriggerType typ = trigger.TriggerType;

                        if (typ == TaskTriggerType.Weekly)
                        {
                            WeeklyTrigger weeklyTrigger = (WeeklyTrigger)trigger;
DaysOfTheWeek = trigger.DaysOfWeek;
// i always get sunday ?
                    }
                }

Jun 18, 2012 at 7:40 PM

Will you try using the assemblies in the zip file found at http://taskscheduler.codeplex.com/workitem/10118 and let me know if you're still experiencing the problem under XP?

Jun 19, 2012 at 8:32 AM

Wow, fast answer :-)

I will try it and let you know!

Jun 19, 2012 at 8:52 AM

Thank you very very much, it works!

Jun 19, 2012 at 3:55 PM

I'll officially release those bits you tested as 1.8.3 later today.