![](/img/trans.png)
[英]Triggering event in foreground when background task is running at the same time?
[英]Task Scheduler - When the event is added to the event log the created task not running
这是我用来创建任务并将其绑定到事件日志的代码,在执行一些操作后,我可以在事件日志中看到创建了新的事件日志,但任务没有被盯着,这里做错了什么?
public void CreateTaskSchedulerTask(Trigger trigger, string name,string description, string path, string arguments, string workingDirectory = null)//"Remove unnecessary dependencies"
{
TaskDefinition td = TaskService.Instance.NewTask();
td.Triggers.Add(trigger);
//td.Principal.LogonType = TaskLogonType.InteractiveToken;
td.RegistrationInfo.Description = description;
td.Actions.Add(new ExecAction(path/*"notepad.exe"*/, arguments/*"c:\\test.log"*/, workingDirectory));
td.Settings.Enabled = true;
td.Settings.Priority = System.Diagnostics.ProcessPriorityClass.Normal;
td.Settings.StartWhenAvailable = true;
td.Settings.DisallowStartIfOnBatteries = false;
td.Settings.StopIfGoingOnBatteries = false;
// td.Settings.RunOnlyIfLoggedOn = false;
TaskService.Instance.RootFolder.RegisterTaskDefinition(name, td);
}
public EventTrigger CreateEventTrigger(string log, string source, int? eventId)//"Microsoft-Windows-AppXDeploymentServer/Operational", "AppXDeployment-Server", 400
{
return new EventTrigger(log, source, eventId);
}
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.