[英]TaskService not working
我正在嘗試編寫一些代碼,在一段時間后在我的本地工作站上取消任務,但目前我在完成工作時遇到了問題。
下面是我正在運行的代碼。
using System;
using Microsoft.Win32.TaskScheduler;
namespace TaskSchedularExamplw
{
class Program
{
static void Main(string[] args)
{
Console.WriteLine("Task Started");
using (TaskService ts = new TaskService())
{
TaskDefinition t = ts.NewTask();
t.Triggers.Add(new TimeTrigger() { StartBoundary = DateTime.Now, Enabled = true });
t.Principal.LogonType = TaskLogonType.InteractiveToken;
TimeTrigger tt = (TimeTrigger)t.Triggers.Add(new TimeTrigger() { StartBoundary = DateTime.Now, Enabled = true });
tt.Repetition.Duration = TimeSpan.FromHours(1);
tt.Repetition.Interval = TimeSpan.FromMinutes(1);
t.Actions.Add(new ExecAction(@"C:\Program Files (x86)\Notepad++\notepad++.exe", "c:\\test.txt", null));
const string taskName = "Test";
ts.RootFolder.RegisterTaskDefinition(taskName, t);
var runningTasks=ts.GetRunningTasks();
}
Console.ReadLine();
}
}
}
有人可以告訴我我在這里做錯了什么。
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.