Class VirtualTimeSchedulerBase<TAbsolute, TRelative>
Base class for virtual time schedulers.
Inheritance
Inherited Members
Namespace: System.Reactive.Concurrency
Assembly: System.Reactive.Linq.dll
Syntax
public abstract class VirtualTimeSchedulerBase<TAbsolute, TRelative> : IScheduler, IServiceProvider, IStopwatchProvider where TAbsolute : IComparable<TAbsolute>
Type Parameters
Name | Description |
---|---|
TAbsolute | Absolute time representation type. |
TRelative | Relative time representation type. |
Constructors
| Improve this Doc View SourceVirtualTimeSchedulerBase()
Creates a new virtual time scheduler with the default value of TAbsolute as the initial clock value.
Declaration
protected VirtualTimeSchedulerBase()
VirtualTimeSchedulerBase(TAbsolute, IComparer<TAbsolute>)
Creates a new virtual time scheduler with the specified initial clock value and absolute time comparer.
Declaration
protected VirtualTimeSchedulerBase(TAbsolute initialClock, IComparer<TAbsolute> comparer)
Parameters
Type | Name | Description |
---|---|---|
TAbsolute | initialClock | Initial value for the clock. |
IComparer<TAbsolute> | comparer | Comparer to determine causality of events based on absolute time. |
Exceptions
Type | Condition |
---|---|
ArgumentNullException |
|
Properties
| Improve this Doc View SourceClock
Gets the scheduler's absolute time clock value.
Declaration
public TAbsolute Clock { get; protected set; }
Property Value
Type | Description |
---|---|
TAbsolute |
Comparer
Gets the comparer used to compare absolute time values.
Declaration
protected IComparer<TAbsolute> Comparer { get; }
Property Value
Type | Description |
---|---|
IComparer<TAbsolute> |
IsEnabled
Gets whether the scheduler is enabled to run work.
Declaration
public bool IsEnabled { get; }
Property Value
Type | Description |
---|---|
Boolean |
Now
Gets the scheduler's notion of current time.
Declaration
public DateTimeOffset Now { get; }
Property Value
Type | Description |
---|---|
DateTimeOffset |
Methods
| Improve this Doc View SourceAdd(TAbsolute, TRelative)
Adds a relative time value to an absolute time value.
Declaration
protected abstract TAbsolute Add(TAbsolute absolute, TRelative relative)
Parameters
Type | Name | Description |
---|---|---|
TAbsolute | absolute | Absolute time value. |
TRelative | relative | Relative time value to add. |
Returns
Type | Description |
---|---|
TAbsolute | The resulting absolute time sum value. |
AdvanceBy(TRelative)
Advances the scheduler's clock by the specified relative time, running all work scheduled for that timespan.
Declaration
public void AdvanceBy(TRelative time)
Parameters
Type | Name | Description |
---|---|---|
TRelative | time | Relative time to advance the scheduler's clock by. |
Exceptions
Type | Condition |
---|---|
ArgumentOutOfRangeException |
|
InvalidOperationException | The scheduler is already running. VirtualTimeScheduler doesn't support running nested work dispatch loops. To simulate time slippage while running work on the scheduler, use Sleep(TRelative). |
AdvanceTo(TAbsolute)
Advances the scheduler's clock to the specified time, running all work till that point.
Declaration
public void AdvanceTo(TAbsolute time)
Parameters
Type | Name | Description |
---|---|---|
TAbsolute | time | Absolute time to advance the scheduler's clock to. |
Exceptions
Type | Condition |
---|---|
ArgumentOutOfRangeException |
|
InvalidOperationException | The scheduler is already running. VirtualTimeScheduler doesn't support running nested work dispatch loops. To simulate time slippage while running work on the scheduler, use Sleep(TRelative). |
GetNext()
Gets the next scheduled item to be executed.
Declaration
protected abstract IScheduledItem<TAbsolute> GetNext()
Returns
Type | Description |
---|---|
IScheduledItem<TAbsolute> | The next scheduled item. |
GetService(Type)
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.
Declaration
protected virtual object GetService(Type serviceType)
Parameters
Type | Name | Description |
---|---|---|
Type | serviceType | Scheduler service interface type to discover. |
Returns
Type | Description |
---|---|
Object | Object implementing the requested service, if available; null otherwise. |
Schedule<TState>(TState, DateTimeOffset, Func<IScheduler, TState, IDisposable>)
Schedules an action to be executed at dueTime.
Declaration
public IDisposable Schedule<TState>(TState state, DateTimeOffset dueTime, Func<IScheduler, TState, IDisposable> action)
Parameters
Type | Name | Description |
---|---|---|
TState | state | State passed to the action to be executed. |
DateTimeOffset | dueTime | Absolute time at which to execute the action. |
Func<IScheduler, TState, IDisposable> | action | Action to be executed. |
Returns
Type | Description |
---|---|
IDisposable | The disposable object used to cancel the scheduled action (best effort). |
Type Parameters
Name | Description |
---|---|
TState | The type of the state passed to the scheduled action. |
Exceptions
Type | Condition |
---|---|
ArgumentNullException |
|
Schedule<TState>(TState, Func<IScheduler, TState, IDisposable>)
Schedules an action to be executed.
Declaration
public IDisposable Schedule<TState>(TState state, Func<IScheduler, TState, IDisposable> action)
Parameters
Type | Name | Description |
---|---|---|
TState | state | State passed to the action to be executed. |
Func<IScheduler, TState, IDisposable> | action | Action to be executed. |
Returns
Type | Description |
---|---|
IDisposable | The disposable object used to cancel the scheduled action (best effort). |
Type Parameters
Name | Description |
---|---|
TState | The type of the state passed to the scheduled action. |
Exceptions
Type | Condition |
---|---|
ArgumentNullException |
|
Schedule<TState>(TState, TimeSpan, Func<IScheduler, TState, IDisposable>)
Schedules an action to be executed after dueTime.
Declaration
public IDisposable Schedule<TState>(TState state, TimeSpan dueTime, Func<IScheduler, TState, IDisposable> action)
Parameters
Type | Name | Description |
---|---|---|
TState | state | State passed to the action to be executed. |
TimeSpan | dueTime | Relative time after which to execute the action. |
Func<IScheduler, TState, IDisposable> | action | Action to be executed. |
Returns
Type | Description |
---|---|
IDisposable | The disposable object used to cancel the scheduled action (best effort). |
Type Parameters
Name | Description |
---|---|
TState | The type of the state passed to the scheduled action. |
Exceptions
Type | Condition |
---|---|
ArgumentNullException |
|
ScheduleAbsolute<TState>(TState, TAbsolute, Func<IScheduler, TState, IDisposable>)
Schedules an action to be executed at dueTime.
Declaration
public abstract IDisposable ScheduleAbsolute<TState>(TState state, TAbsolute dueTime, Func<IScheduler, TState, IDisposable> action)
Parameters
Type | Name | Description |
---|---|---|
TState | state | State passed to the action to be executed. |
TAbsolute | dueTime | Absolute time at which to execute the action. |
Func<IScheduler, TState, IDisposable> | action | Action to be executed. |
Returns
Type | Description |
---|---|
IDisposable | The disposable object used to cancel the scheduled action (best effort). |
Type Parameters
Name | Description |
---|---|
TState | The type of the state passed to the scheduled action. |
ScheduleRelative<TState>(TState, TRelative, Func<IScheduler, TState, IDisposable>)
Schedules an action to be executed at dueTime.
Declaration
public IDisposable ScheduleRelative<TState>(TState state, TRelative dueTime, Func<IScheduler, TState, IDisposable> action)
Parameters
Type | Name | Description |
---|---|---|
TState | state | State passed to the action to be executed. |
TRelative | dueTime | Relative time after which to execute the action. |
Func<IScheduler, TState, IDisposable> | action | Action to be executed. |
Returns
Type | Description |
---|---|
IDisposable | The disposable object used to cancel the scheduled action (best effort). |
Type Parameters
Name | Description |
---|---|
TState | The type of the state passed to the scheduled action. |
Sleep(TRelative)
Advances the scheduler's clock by the specified relative time.
Declaration
public void Sleep(TRelative time)
Parameters
Type | Name | Description |
---|---|---|
TRelative | time | Relative time to advance the scheduler's clock by. |
Exceptions
Type | Condition |
---|---|
ArgumentOutOfRangeException |
|
Start()
Starts the virtual time scheduler.
Declaration
public void Start()
StartStopwatch()
Starts a new stopwatch object.
Declaration
public IStopwatch StartStopwatch()
Returns
Type | Description |
---|---|
IStopwatch | New stopwatch object; started at the time of the request. |
Stop()
Stops the virtual time scheduler.
Declaration
public void Stop()
ToDateTimeOffset(TAbsolute)
Converts the absolute time value to a DateTimeOffset value.
Declaration
protected abstract DateTimeOffset ToDateTimeOffset(TAbsolute absolute)
Parameters
Type | Name | Description |
---|---|---|
TAbsolute | absolute | Absolute time value to convert. |
Returns
Type | Description |
---|---|
DateTimeOffset | The corresponding DateTimeOffset value. |
ToRelative(TimeSpan)
Converts the TimeSpan value to a relative time value.
Declaration
protected abstract TRelative ToRelative(TimeSpan timeSpan)
Parameters
Type | Name | Description |
---|---|---|
TimeSpan | timeSpan | TimeSpan value to convert. |
Returns
Type | Description |
---|---|
TRelative | The corresponding relative time value. |
Explicit Interface Implementations
| Improve this Doc View SourceIServiceProvider.GetService(Type)
Declaration
object IServiceProvider.GetService(Type serviceType)
Parameters
Type | Name | Description |
---|---|---|
Type | serviceType |
Returns
Type | Description |
---|---|
Object |