Creates a child job.
Namespace: AGI.Parallel.Infrastructure
Assembly: AGI.Parallel.Infrastructure (in AGI.Parallel.Infrastructure.dll) Version: 1.2.0.275 (1.2.0.275)

Syntax

C#
IJob CreateChildJob(
        bool yieldAllResourcesToChildren
)
Visual Basic
Function CreateChildJob ( _
        yieldAllResourcesToChildren As Boolean _
) As IJob

Parameters

yieldAllResourcesToChildren
Type: System..::..Boolean
if set to true yields all resources to children once the job is submitted.

Return Value

Job which can be submitted back to same job scheduler that the current task was submitted to.

Examples

  Copy imageCopy
using System;
using AGI.Parallel.Client;
using AGI.Parallel.Infrastructure;

namespace CodeSamples
{
    class Program
    {
        static void Main(string[] args)
        {
            using (IJobScheduler scheduler = new ClusterJobScheduler("localhost"))
            {
                scheduler.Connect();

                Job job = scheduler.CreateJob();
                job.AddTask(new ParentTask());
                job.Submit();
                job.WaitUntilDone();

                Console.WriteLine(job.Tasks[0].Result);
            }

            /*
             * The output of the application should resemble:
             * From Parent -> From Child
             */
        }

        [Serializable]
        public class ParentTask : Task
        {
            public override void Execute()
            {
                // Get the instance of the job scheduler context
                IJobSchedulerContext schedulerContext = this.GetProperty<IJobSchedulerContext>(TaskProperties.JobSchedulerContext);

                // Create a child job by calling CreateChildJob.
                IJob job = schedulerContext.CreateChildJob();
                Task task = new ChildTask();
                job.AddTask(task);
                job.Submit();
                job.WaitUntilDone();

                this.Result = "From Parent -> " + task.Result;
            }
        }

        [Serializable]
        public class ChildTask : Task
        {
            public override void Execute()
            {
                this.Result = "From Child";
            }
        }
    }
}

See Also