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

Problem adding a task on a windows server 2003

Aug 11, 2011 at 8:37 AM

Hi,

 

I'm experiencing a little problem with a task scheduling on a windows server 2003.


This code works on a windows 7:

class Program
    {
        static void Main(string[] args)
        {
            try
            {
                AddTask();
            }catch(Exception ex)
            {
                Console.WriteLine(ex.ToString());
            }

            Console.ReadLine();
        }

        private static void AddTask()
        {
            using (TaskService ts = new TaskService())
            {

                // Create a new task definition and assign properties
                TaskDefinition td = ts.NewTask();
                td.RegistrationInfo.Description = "Task description";

                // Create a trigger that will fire the task at this time every other day
                DailyTrigger dailyTrigger = new DailyTrigger() { DaysInterval = 1 };
                dailyTrigger.Repetition.Interval = TimeSpan.FromHours(1);
                dailyTrigger.StartBoundary = DateTime.Now.AddMinutes(5);
                td.Triggers.Add(dailyTrigger);

                // Create an action that will launch Notepad whenever the trigger fires
                td.Actions.Add(new ExecAction("notepad.exe"));

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


            }
        }
    }

But not on a windows server 2003. They are both in 32 bits.

I suppose that windows server supports only 1.0 library actions, but I don't see which action can be of the 2.0 library.

What did I wrong?

Aug 11, 2011 at 9:04 AM

I just saw that if I remove the line for the Repetition configuration, I can the task. But this seems to be possible with the windows configuration, so I suppose it should be possible through this taskscheduler

Coordinator
Aug 11, 2011 at 2:44 PM

You must also set a Repetition.Duration value that is less than the Repetition.Interval value you have specified under V1.

Aug 11, 2011 at 3:20 PM

It was that! Thank you!