Language: C#

View on GitHub to download or comment.

See the Client API Examples Introduction for additional information and prerequisites.

Samples index

This sample shows how to link two jobs using a Job Trigger.

In this example, the Job 3 waits for successful completion of both Job 1 and Job 2.

samples.cs
	using (var session = Scheduler.Connect(".", LoginAuthenticationType.Windows, "", ""))
	{
		using (var context = session.NewDataContext())
		{
			//retrieve the jobs
			var job1=context.GetJob("Job 1");
			var job2 = context.GetJob("Job 2");
			var job3 = context.GetJob("Job 3");

			//create a Job Trigger
			var jobTrigger = context.CreateObject(ClassID.JobTrigger) as JobTrigger;
			jobTrigger.TriggerOptions = JobTriggerOptions.WaitForAll;
			
			//create and add a JobTriggerTarget for each of the jobs that you need to wait on
			var target=context.CreateObject(ClassID.JobTriggerTarget) as JobTriggerTarget;
			target.TargetJobOID=job1.OID;
			target.TargetInstance= JobConditionInstance.MostRecentSinceLastExecution;
			target.TriggerType = JobTriggerType.JobSucceeded;
			jobTrigger.Targets.Add(target);

			target = context.CreateObject(ClassID.JobTriggerTarget) as JobTriggerTarget;
			target.TargetJobOID = job2.OID;
			target.TargetInstance = JobConditionInstance.MostRecentSinceLastExecution;
			target.TriggerType = JobTriggerType.JobSucceeded;
			jobTrigger.Targets.Add(target);

			job3.Triggers.Add(jobTrigger);
			job3.Save();
		}

	}

Comments

View on GitHub to comment.