IJobCancelOnTaskFailure Property |
Namespace: AGI.Parallel.Infrastructure
using System; using System.Threading; 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.CancelOnTaskFailure = true; for (int i = 0; i < 3; ++i) { job.AddTask(new WaitTask()); } // This task will fail. Watch as the other tasks are canceled. job.AddTask(new FailureTask()); job.Submit(); job.WaitUntilDone(); for (int i = 0; i < 4; ++i) { Console.WriteLine("Task #{0} Status {1}", i + 1, job.Tasks[i].TaskStatus); } } /* * The output of the application should resemble: * Task #1 Status Canceled * Task #2 Status Canceled * Task #3 Status Canceled * Task #4 Status Failed */ } [Serializable] class WaitTask : Task { public override void Execute() { for (int i = 0; i < 100; ++i) { Thread.Sleep(100); } } } [Serializable] class FailureTask : Task { public override void Execute() { Thread.Sleep(100); throw new Exception("Failure"); } } } }
STK Parallel Computing Server 2.9 API for .NET