Interface ITimeSyncManager
Measures the offset between the clock of a server (or an NTP server) and the local clock and keeps it up to date. A connector initializes it on connect, starts the periodic refresh while connected and stops it on disconnect.
public interface ITimeSyncManager : ILoggerSource
- Inherited Members
- Extension Methods
Properties
IsInitialized
True after the first successful measurement of TimeDifference; it stays true after Stop().
bool IsInitialized { get; }
Property Value
- bool
TimeDifference
Shows how much the data provider's clock is ahead of the local clock
TimeSpan TimeDifference { get; }
Property Value
- TimeSpan
Remarks
Negative when the server clock is behind. System.TimeSpan.Zero until the first measurement. The built-in managers take the median of three samples, each compensated for half of the request round trip.
TimeProvider
The clock that consumers of the manager read the current local time from; TimeProvider.System by default.
The built-in managers do not use it for their own measurements.
TimeProvider TimeProvider { get; set; }
Property Value
- TimeProvider
Methods
InitAsync(CancellationToken)
Measures TimeDifference once and sets IsInitialized.
Task InitAsync(CancellationToken cancellationToken = default)
Parameters
cancellationTokenCancellationTokenCancels the measurement.
Returns
- Task
A task that completes when the measurement is done.
Exceptions
- TimeoutException
The built-in managers fail the task when the average network latency of the samples exceeds 15 seconds.
Start()
Starts the background refresh of TimeDifference (every minute in the built-in managers); refresh errors are logged, not thrown. The built-in managers throw System.InvalidOperationException when the refresh is already started; a wrapper around a shared manager does nothing.
void Start()
Stop()
Stops the background refresh started by Start(); does nothing when it is not running. The last measured TimeDifference is kept.
void Stop()