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)
{
try
{
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;
this.StatusHandler.TaskCompleted(0);
}
}