我正在开发一个 C# WPF 项目。我需要允许用户创建计划任务并将其添加到 Windows 任务计划程序。
我怎样才能做到这一点以及我需要什么使用指令和参考资料,因为我在搜索互联网时没有找到太多信息。
您可以使用任务计划程序托管包装 https://github.com/dahall/taskscheduler:
using System;
using Microsoft.Win32.TaskScheduler;
class Program
{
static void Main(string[] args)
{
// Get the service on the local machine
using (TaskService ts = new TaskService())
{
// Create a new task definition and assign properties
TaskDefinition td = ts.NewTask();
td.RegistrationInfo.Description = "Does something";
// Create a trigger that will fire the task at this time every other day
td.Triggers.Add(new DailyTrigger { DaysInterval = 2 });
// Create an action that will launch Notepad whenever the trigger fires
td.Actions.Add(new ExecAction("notepad.exe", "c:\\test.log", null));
// Register the task in the root folder
ts.RootFolder.RegisterTaskDefinition(@"Test", td);
// Remove the task we just created
ts.RootFolder.DeleteTask("Test");
}
}
}
或者你可以使用native http://msdn.microsoft.com/en-us/library/aa384006%28v=vs.85%29.aspxAPI 或去石英网 http://www.quartz-scheduler.net/. See this https://stackoverflow.com/q/5115105/625332了解详情。
本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)