Creates a child job and yields all resources to children.
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()
Visual Basic
Function CreateChildJob As IJob

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