-1

I want to run my schedule task after 3 second, for that i have written code in my WPF application.

 using (var ts = new TaskService())
 { 
     TaskDefinition td = ts.NewTask();
     td.Settings.MultipleInstances = TaskInstancesPolicy.IgnoreNew;
     td.RegistrationInfo.Description = "TestAPP";

     var trigger = new TimeTrigger();
     trigger.Repetition.Interval = TimeSpan.FromSeconds(3000);
     lblProcess.Content = DateTime.Now.Second; //print current second in a label. 
     td.Triggers.Add(trigger);

     td.Actions.Add(new ExecAction(System.Reflection.Assembly.GetExecutingAssembly().Location, null, System.IO.Path.GetDirectoryName(System.Reflection.Assembly.GetExecutingAssembly().Location)));

     ts.RootFolder.RegisterTaskDefinition(@"TestTask", td);
 }

Here i want to check that after ruining from VS, it will run every 3 second or not, so I've print current second to the label lblProcess.

But it does not updated on every 3 second, Am I doing anything wrong?

EDIT-1:

I've read this before : Creating Scheduled Tasks

There is nothing like to how to check.

Edit-2:

If i use 3.0 instead of 3000 then it's give me an error.

Specified argument was out of the range of valid values.Parameter name: Interval

Community
  • 1
  • 1
Barry Allen
  • 81
  • 2
  • 14

2 Answers2

1
TimeSpan.FromSeconds(3);

When passing 3000 you input 3000 seconds.

https://msdn.microsoft.com/en-us/library/system.timespan.fromseconds(v=vs.110).aspx

Pudding
  • 533
  • 1
  • 6
  • 23
  • I just hit `F12` and method having summery like this *// Parameters:// value:// A number of seconds, accurate to the nearest millisecond.* – Barry Allen Sep 27 '16 at 09:17
  • And read from link which you posted : `A number of seconds, accurate to the nearest millisecond` – Barry Allen Sep 27 '16 at 09:18
  • True. It is accurate to the nearest millisecond but to input milliseconds you use a double data type not int. So it takes 3000 as 3000 seconds not 3.000 seconds – Pudding Sep 27 '16 at 09:18
  • If use like you suggested it's give me an error of **Specified argument was out of the range of valid values.Parameter name: Interval** – Barry Allen Sep 27 '16 at 09:21
  • **You cannot set interval in Task Scheduler less than one minute**, it's not *TimeSpan.FromSeconds(3);.* Issue – Barry Allen Sep 27 '16 at 11:18
1

You cannot set interval in Task Scheduler less than one minute

oldovets
  • 695
  • 4
  • 9
  • OK, Can you please give me some reference, where it stated – Barry Allen Sep 27 '16 at 09:52
  • You can look here: https://social.technet.microsoft.com/Forums/windows/en-US/a0a06158-4c94-4f2a-ac32-3e1e555fd54d/how-to-run-task-every-30-seconds?forum=w7itprogeneral And here is the solution to your problem: http://stackoverflow.com/questions/7769635/windows-task-scheduler-to-execute-tasks-in-seconds (scheduling 59 triggers) – oldovets Sep 27 '16 at 10:33