Problem

You want to report progress from the task to the client for monitoring purposes.

Solution

First, to receive the progress messages sent from the task to the client, subscribe to the job's TaskProgressUpdated event or the task's ProgressUpdated event.

C#  Copy imageCopy
job.TaskProgressUpdated += new EventHandler<TaskProgressEventArgs>(Job_TaskProgressUpdated);

Then, on the task, call SetProgress. The values passed to SetProgress will be received on the client's progress event handling method.

C#  Copy imageCopy
this.SetProgress(40, 4);
C#  Copy imageCopy
using System;
using System.Collections.Generic;
using System.Diagnostics;
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 ProgressTask());

                // Subscribe to TaskProgressUpdated
                job.TaskProgressUpdated += new EventHandler<TaskProgressEventArgs>(Job_TaskProgressUpdated);

                job.Submit();
                job.WaitUntilDone();
            }

            /*
             * The output of the application should resemble:
             * 0 1
             * 20 B
             * 40 4
             * 60 D
             * 80 E
             */
        }

        private static void Job_TaskProgressUpdated(object sender, TaskProgressEventArgs e)
        {
            Console.WriteLine("{0} {1}", e.Description.Progress, e.Description.AdditionalInformation);
        }

        [Serializable]
        public class ProgressTask : Task
        {
            public override void Execute()
            {
                this.SetProgress(0, 1);
                System.Threading.Thread.Sleep(1000);
                this.SetProgress(20, "B");
                System.Threading.Thread.Sleep(1000);
                this.SetProgress(40, 4);
                System.Threading.Thread.Sleep(1000);
                this.SetProgress(60, "D");
                System.Threading.Thread.Sleep(1000);
                this.SetProgress(80, "E");
                System.Threading.Thread.Sleep(1000);
            }
        }
    }
}

Discussion

If a job could potentially take a long time to finish, reporting the progress of tasks while the task is running helps to notify the user how long the task could take. You can read more about working with task progress here.

To view the progress through the monitoring applications, open the task monitor (through the coordinator or agent tray application). Right click on the column headings and then click on "Status Description" on the drop down menu.

Show Status Description

Once the Status Description column is visible, the value of the task progress description can be seen. This is shown in the example above.

Monitor Task Progress UsingUI

See Also