Class Ticker
- Namespace
- Bluetooth.Core.Infrastructure.Scheduling
- Assembly
- Bluetooth.Core.dll
Implementation of the ITicker interface.
public sealed class Ticker : ITicker, IDisposable
- Inheritance
-
Ticker
- Implements
- Inherited Members
Constructors
Ticker(ILogger<Ticker>, IOptions<TickerOptions>)
Initializes a new instance of the Ticker class.
public Ticker(ILogger<Ticker> logger, IOptions<TickerOptions> options)
Parameters
loggerILogger<Ticker>The logger instance.
optionsIOptions<TickerOptions>The ticker options.
Methods
Dispose()
Performs application-defined tasks associated with freeing, releasing, or resetting unmanaged resources.
public void Dispose()
Register(string, TimeSpan, Action, bool)
Registers a callback to be invoked every period.
The callback should be fast and non-blocking; if it needs async work, use the async overload.
Returns a subscription that should be disposed to unregister.
public IDisposable Register(string name, TimeSpan period, Action tick, bool runImmediately = false)
Parameters
namestringThe name of the registration.
periodTimeSpanThe period between invocations.
tickActionThe callback to invoke.
runImmediatelyboolWhether to run the callback immediately upon registration.
Returns
- IDisposable
A subscription that should be disposed to unregister.
Register(string, TimeSpan, Func<CancellationToken, Task>, bool)
Registers an async callback to be invoked every period.
The ticker will avoid overlapping executions for the same registration.
Returns a subscription that should be disposed to unregister.
public IDisposable Register(string name, TimeSpan period, Func<CancellationToken, Task> tickAsync, bool runImmediately = false)
Parameters
namestringThe name of the registration.
periodTimeSpanThe period between invocations.
tickAsyncFunc<CancellationToken, Task>The async callback to invoke.
runImmediatelyboolWhether to run the callback immediately upon registration.
Returns
- IDisposable
A subscription that should be disposed to unregister.