Game Development Reference
In-Depth Information
public JobSpan(Scheduler schedule, TimeSpan interval)
: base(schedule, ScheduleMode.Span)
{
base.JobTimer = new Timer(interval.TotalMilliseconds);
base.JobTimer.Elapsed += new ElapsedEventHandler(ElapsedInterval);
base.JobTimer.AutoReset = true;
}
}
The final step in implementing a job scheduler is to develop the scheduling com-
ponent itself. At this point, we have two different flavors of jobs that can be regis-
tered: jobs that execute at a particular date and time and jobs that can execute at a
given interval on a recurring basis. Basically, each JobBase object has an internal
timer that is configured for the job, and it is the responsibility of the scheduler to
manage the timers and track all registered jobs. While relatively simple, the sched-
uler is an important part of an automation system. The following code describes
the implementation of the scheduler in its entirety.
using System;
using System.Collections.Generic;
public class Scheduler : IDisposable
{
private SortedList<Object, JobBase> _jobList;
public SortedList<Object, JobBase> JobList
{
get { return _jobList; }
}
public Scheduler()
{
_jobList = new SortedList<Object, JobBase>();
}
public void Add(object key, JobBase job)
{
try
{
_jobList.Add(key, job);
job.UserData = key;
job.JobTimer.Start();
Search Nedrilad ::




Custom Search