<PackageReference Include="System.Reactive" Version="4.1.4" />

VirtualTimeSchedulerBase<TAbsolute, TRelative>

public abstract class VirtualTimeSchedulerBase<TAbsolute, TRelative> : IScheduler, IServiceProvider, IStopwatchProvider where TAbsolute : IComparable<TAbsolute>
Base class for virtual time schedulers.
public TAbsolute Clock { get; protected set; }

Gets the scheduler's absolute time clock value.

protected IComparer<TAbsolute> Comparer { get; }

Gets the comparer used to compare absolute time values.

public bool IsEnabled { get; }

Gets whether the scheduler is enabled to run work.

public DateTimeOffset Now { get; }

Gets the scheduler's notion of current time.

Creates a new virtual time scheduler with the default value of TAbsolute as the initial clock value.

protected VirtualTimeSchedulerBase(TAbsolute initialClock, IComparer<TAbsolute> comparer)

Creates a new virtual time scheduler with the specified initial clock value and absolute time comparer.

protected abstract TAbsolute Add(TAbsolute absolute, TRelative relative)

Adds a relative time value to an absolute time value.

public void AdvanceBy(TRelative time)

Advances the scheduler's clock by the specified relative time, running all work scheduled for that timespan.

public void AdvanceTo(TAbsolute time)

Advances the scheduler's clock to the specified time, running all work till that point.

protected abstract IScheduledItem<TAbsolute> GetNext()

Gets the next scheduled item to be executed.

protected virtual object GetService(Type serviceType)

Discovers scheduler services by interface type. The base class implementation supports only the IStopwatchProvider service. To influence service discovery - such as adding support for other scheduler services - derived types can override this method.

public IDisposable Schedule<TState>(TState state, Func<IScheduler, TState, IDisposable> action)

Schedules an action to be executed.

public IDisposable Schedule<TState>(TState state, TimeSpan dueTime, Func<IScheduler, TState, IDisposable> action)

Schedules an action to be executed after dueTime.

public IDisposable Schedule<TState>(TState state, DateTimeOffset dueTime, Func<IScheduler, TState, IDisposable> action)

Schedules an action to be executed at dueTime.

public abstract IDisposable ScheduleAbsolute<TState>(TState state, TAbsolute dueTime, Func<IScheduler, TState, IDisposable> action)

Schedules an action to be executed at dueTime.

public IDisposable ScheduleRelative<TState>(TState state, TRelative dueTime, Func<IScheduler, TState, IDisposable> action)

Schedules an action to be executed at dueTime.

public void Sleep(TRelative time)

Advances the scheduler's clock by the specified relative time.

public void Start()

Starts the virtual time scheduler.

Starts a new stopwatch object.

public void Stop()

Stops the virtual time scheduler.

protected abstract DateTimeOffset ToDateTimeOffset(TAbsolute absolute)

Converts the absolute time value to a DateTimeOffset value.

protected abstract TRelative ToRelative(TimeSpan timeSpan)

Converts the TimeSpan value to a relative time value.