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
Name | Type | Description |
---|---|---|
action | Action | The action (method) to execute. |
delay | TimeSpan | The 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
Name | Type | Description |
---|---|---|
action | Action | The action (method) to execute. |
interval | TimeSpan | The time interval between executions. |
delay | TimeSpan | The 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
Name | Type | Description |
---|---|---|
action | Action | The action (method) to execute. |
cron | string | The cron expression. |
timeZone | TimeZoneInfo | The timezone for the scheduled execution. |
delay | TimeSpan | The 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!