|
using System;
namespace ZipMyCode.Service.Tasks
{
/// <summary>
/// Abstract base class for all tasks.
/// </summary>
abstract class TaskBase : ITask
{
#region ITask Members
/// <summary>
/// Event sent when the task is finished.
/// </summary>
public event EventHandler Finished;
/// <summary>
/// Gets the name of the task.
/// </summary>
public string Name { get; protected set; }
/// <summary>
/// Runs the task.
/// </summary>
/// <returns>Status describing the outcome of the task.</returns>
public TaskStatus Run()
{
// Run task
TaskStatus result = InternalRun();
// Send finished event
OnFinished();
// Return result
return result;
}
#endregion
/// <summary>
/// Runs the task.
/// </summary>
/// <returns>Status describing the outcome of the task.</returns>
protected abstract TaskStatus InternalRun();
/// <summary>
/// Sends the Finished event to anybody listening.
/// </summary>
protected virtual void OnFinished()
{
if (Finished != null)
{
Finished(this, EventArgs.Empty);
}
}
}
}
|
By viewing downloads associated with this article you agree to the Terms of Service and the article's licence.
If a file you wish to view isn't highlighted, and is a text file (not binary), please
let us know and we'll add colourisation support for it.
Got my first computer in the 90's and loved it even though it sounded like a coffeemaker.
Now getting paid for designing cool applications, and drinks the coffee instead of listening to it being made.