如何每三秒检查一次计划任务并使用 C# 在标签中打印秒

How to check schedule task every three second and print second in label using c#

我想在 3 秒后 运行 我的计划任务,为此我已经在我的 WPF 应用程序中编写了代码。

 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);
 }

这里我想检查从 VS 破坏后,它是否会每 3 秒 运行,所以我将当前秒打印到标签 lblProcess

但是不是每3秒更新一次,我做错了吗?

EDIT-1:

我以前读过这个:Creating Scheduled Tasks

没有喜欢的怎么查。

编辑-2:

如果我使用 3.0 而不是 3000 那么它会给我一个错误。

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

TimeSpan.FromSeconds(3);

超过 3000 时输入 3000 秒。

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

您不能在任务计划程序中将间隔设置为小于一分钟