0

It seems that if my build step spawns a child process, that process cannot survive the end of the build - it is killed.

But I have a scenario where a child process is triggered in order to complete offline certain operations that the build should not wait for their completion (reporting metrics to Azure AppInsights).

This procedure worked fine in XAML builds, but now that we migrated to vNext it is broken, because the child process is killed when the build ends.

What can be done about it?

mark
  • 59,016
  • 79
  • 296
  • 580

1 Answers1

1

The easiest way is to schedule a task using the task scheduler.

Example using Microsoft.Win32.TaskScheduler NuGet package:

using (var ts = new TaskService())
{
    // Create a new task definition and assign properties
    var td = ts.NewTask();
    td.Triggers.Add(new TimeTrigger(DateTime.Now.AddDays(-1)));
    td.Actions.Add(new ExecAction(MyExe, MyArgs));
    ts.RootFolder.RegisterTaskDefinition(MyTaskName, td).Run();
    ts.RootFolder.DeleteTask(MyTaskName);
}
mark
  • 59,016
  • 79
  • 296
  • 580
jessehouwing
  • 106,458
  • 22
  • 256
  • 341
  • The schedule has to be created and auto deleted when completed. Do you happen to know the details of how can this be done from C#? I can probably google it, but these kinds of details will make your answer truly awesome. – mark Nov 11 '18 at 18:56
  • I know :). Haven't had the time to look it up. There are plenty of examples on setting up a scheduled task from powershell. An online powershell script task would do the trick. Depending on its usage I'd either give it a fixed name and just leave it there or use the build definition ID or something to clean it up afterwards. Then pass that id in as a parameter to the schedules task. – jessehouwing Nov 12 '18 at 11:03
  • 1
    I have taken the liberty to edit your question and add the example code based on what I did for myself. Thanks again. – mark Nov 12 '18 at 12:50