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
TimeSpan.FromSeconds(3);
When passing 3000 you input 3000 seconds.
https://msdn.microsoft.com/en-us/library/system.timespan.fromseconds(v=vs.110).aspx
您不能在任务计划程序中设置间隔少于一分钟
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.