implementing and ITaskHandlerStatus

May 22, 2015 at 6:39 AM
Edited May 22, 2015 at 6:44 AM
i'm trying to schedule a com object implementing ITaskHandler interface
i've download your template project "COMTask"

Registering the task with this code everything works well
TaskService  ts = new TaskService();

TaskDefinition comTd = ts.NewTask();
comTd.RegistrationInfo.Description = "my first schedule on a COM object";

wt = new DailyTrigger();
wt.StartBoundary = new DateTime(DateTime.Today.Year, DateTime.Today.Month, DateTime.Today.Day, 14, 0, 0, 0, DateTimeKind.Local);
wt.Repetition.Interval = TimeSpan.FromMinutes(100);
ComHandlerAction cha = new ComHandlerAction(new Guid("{CE7D4428-8A77-4c5d-8A13-5CAB5D1EC734}"), "mydata");
ts.RootFolder.RegisterTaskDefinition("My COM TAsk", comTd);
now i'd like to implement ITaskHandlerStatus interface in order to get the percentage of completion.

i've noticed that in your project,
into the file "TaskHandlerBase.cs" there is this interface "decorated" with a different "GUID" (different from the other one on the ITaskHandler interface)

so what does it mean? i have to register another COMtask with this guid?
is not sufficent implement this interface(ITaskHandlerStatus) into the com object i've already registered?

i've not understood well how to do

at first i thought to add the ITaskHandlerStatus interface to you COMTask class and implement its methods

your class
public class MyCOMTask : TaskHandlerBase
public class MyCOMTask : TaskHandlerBase, ITaskHandlerStatus
but if so, i don't understand the meaning of the second "GUID"
May 22, 2015 at 2:46 PM
The ITaskHanderStatus interface is exposed through the StatusHandler property of TaskHandlerBase. Suppose you had a task that needed to write information to a log file every few seconds and terminate after 100 entries. You would create a Timer instance inside your TaskHandlerBase inherited class and then have a method like the following that would be called when that Timer's Elapsed event was called:
const int maxWrites = 100;
int writeCount = 0;

void timer_Elapsed(object sender, ElapsedEventArgs e)
  if (writeCount < maxWrites)
      using (StreamWriter wri = File.AppendText(file))
        wri.WriteLine("Log entry {0}", DateTime.Now);

      this.StatusHandler.UpdateStatus((short)(++writeCount / maxWrites), string.Format("Log file started at {0}", lastWriteTime));
    catch { }

  if (writeCount >= maxWrites)
    timer.Enabled = false;
    writeCount = 0;
Marked as answer by dahall on 9/1/2015 at 9:32 AM