You can just run/stop/enable directly on task
rather than on task.Definition.Settings
. The latter is more for providing a default configuration when initially registering the task. If the task already exists and you're just trying to interact with the active instance then you can query for it via the TaskService
:
var task = taskService.RootFolder.GetTasks().First(t => t.Name == "Test");
// To enable/disable
task.Enabled = true;
// Or to run
task.Run();
// Or to stop
task.Stop();
Setting Enabled
or calling Run
or Stop
will immediately affect the active instance and don't need you to re-register the task with the updated definition.
I believe RegisterTaskDefinition
is just needed if you want to update the task definition but not the active instance.