Skip to main content

IMoBroScheduler

Scheduler that can be used to implement recurring tasks (e.g. polling sensor values or an external API).

info

Scheduled tasks will be put on halt whenever IMoBroPlugin.Pause is invoked on the plugin and automatically resumed once IMoBroPlugin.Resume is invoked.

Functions

OneOff(Action, TimeSpan)

Schedules a one-off task that will only be called once

Parameters

NameTypeDescription
actionActionThe action to execute
delayTimeSpanThe delay before the execution

Example

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

Interval(Action, TimeSpan, TimeSpan)

Schedules a recurring task that will be called in the given interval

Parameters

NameTypeDescription
actionActionThe action to execute
intervalTimeSpanThe recurring interval
delayTimeSpanThe delay before the execution

Example

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

Cron(Action, string, TimeZoneInfo, TimeSpan)

Schedules a recurring task based on a cron string
Cron string format

Parameters

NameTypeDescription
actionActionThe action to execute
cronstringThe cron string
timeZoneTimeZoneInfoThe timezone
delayTimeSpanThe delay before the execution

Example

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