-
Notifications
You must be signed in to change notification settings - Fork 18
Tutorial
Working with Chroniton is easy.
Simply use the singularity to schedule a job and start the singularity.
###Get the singularity
ISingularity singularity = Singularity.Instance;
or
ISingularityFactory factory = new SingularityFactory();
ISingularity singularity = factory.GetSingularity();
###Construct an IJob
The library has a SimpleJob
and SimpleParameterizedJob
built for you which take Action<DateTime>
in their constructors. You can also create your own IJob
implementation.
var job = new SimpleJob(scheduledTime => Console.WriteLine("Hello World"));
var parameterizdeJob = new SimpleParameterizedJob<string>((parameter, scheduledTime) =>
Console.WriteLine(parameter));
###Construct an ISchedule
You can use one of the built in schedules or create your own ISchedule
. The ConstantSchedule
will run a job continuously.
var schedule = new ConstantSchedule();
The Singularity
does all the work of managing how jobs and schedules interact. It has several overloads for scheduling jobs.
bool runNow = true;
singularity.ScheduleJob(schedule, job, runNow);
var startTime = DateTime.UtcNow;
singularity.ScheduleParameterizedJob(schedule, parameterizdeJob, "Hello World", startTime);
In the above code if runNow
were set to false, the schedule would be called to get the first run. There are also overloads to make the first run happen at a specified time. ScheduleJob()
returns an IScheduledJob which can be used to cancel the job if needed.
singularity.StopScheduledJob(scheduledJob);
singularity.Start();