How to spawn an offline process from a TFS vNext build step that would last beyond the build?

33 views Asked by At

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?

1

There are 1 answers

3
jessehouwing On BEST ANSWER

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