Join GitHub today
GitHub is home to over 28 million developers working together to host and review code, manage projects, and build software together.Sign up
Working with Chroniton is easy.
Simply use the singularity to schedule a job and start the singularity.
###Get the singularity
ISingularity singularity = Singularity.Instance;
ISingularityFactory factory = new SingularityFactory(); ISingularity singularity = factory.GetSingularity();
The library has a
SimpleParameterizedJob built for you which take
Action<DateTime> in their constructors. You can also create your own
var job = new SimpleJob(scheduledTime => Console.WriteLine("Hello World")); var parameterizdeJob = new SimpleParameterizedJob<string>((parameter, scheduledTime) => Console.WriteLine(parameter));
You can use one of the built in schedules or create your own
ConstantSchedule will run a job continuously.
var schedule = new ConstantSchedule();
Schedule the Job
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.
Start the singularity