Tutorial

Leonard Sperry edited this page Jul 23, 2016 · 6 revisions

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();

Schedule the Job

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);

Start the singularity

    singularity.Start();
Clone this wiki locally
You can’t perform that action at this time.
You signed in with another tab or window. Reload to refresh your session. You signed out in another tab or window. Reload to refresh your session.
Press h to open a hovercard with more details.