Skip to main content

IMoBroScheduler

The IMoBroScheduler provides functionality to schedule recurring tasks such as polling sensor values or fetching data from an external API.


Functions

OneOff(Action, TimeSpan)

Schedules a one-off task that will execute only once.

Parameters

NameTypeDescription
actionActionThe action (method) to execute.
delayTimeSpanThe time delay before execution begins.

Example

_scheduler.OneOff(UpdateDynamicMetrics, TimeSpan.FromSeconds(2));

Interval(Action, TimeSpan, TimeSpan)

Schedules a recurring task that executes at a specific interval.

Parameters

NameTypeDescription
actionActionThe action (method) to execute.
intervalTimeSpanThe time interval between executions.
delayTimeSpanThe initial delay before the first execution.

Example

_scheduler.Interval(UpdateMetrics, TimeSpan.FromSeconds(2), TimeSpan.FromSeconds(5));

Cron(Action, string, TimeZoneInfo, TimeSpan)

Schedules a recurring task based on a cron expression.
For reference on cron string format, visit Quartz Cron Documentation.

Parameters

NameTypeDescription
actionActionThe action (method) to execute.
cronstringThe cron expression.
timeZoneTimeZoneInfoThe timezone for the scheduled execution.
delayTimeSpanThe initial delay before the first execution.

Example

_scheduler.Cron(UpdateMetrics, "* * * * ? *", TimeZoneInfo.Utc, TimeSpan.FromSeconds(5));

This guide provides concise details on the usage of IMoBroScheduler for both one-time and recurring tasks. Make use of the provided examples as a reference to correctly implement the scheduler in your applications!