Search Results for

    Show / Hide Table of Contents

    Class VirtualTimeSchedulerBase<TAbsolute, TRelative>

    Base class for virtual time schedulers.

    Inheritance
    Object
    VirtualTimeSchedulerBase<TAbsolute, TRelative>
    HistoricalSchedulerBase
    VirtualTimeScheduler<TAbsolute, TRelative>
    Implements
    IScheduler
    IServiceProvider
    IStopwatchProvider
    Inherited Members
    Object.Equals(Object)
    Object.Equals(Object, Object)
    Object.GetHashCode()
    Object.GetType()
    Object.MemberwiseClone()
    Object.ToString()
    Object.ReferenceEquals(Object, Object)
    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 Source

    VirtualTimeSchedulerBase()

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

    Declaration
    protected VirtualTimeSchedulerBase()
    | Improve this Doc View Source

    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

    comparer is null.

    Properties

    | Improve this Doc View Source

    Clock

    Gets the scheduler's absolute time clock value.

    Declaration
    public TAbsolute Clock { get; protected set; }
    Property Value
    Type Description
    TAbsolute
    | Improve this Doc View Source

    Comparer

    Gets the comparer used to compare absolute time values.

    Declaration
    protected IComparer<TAbsolute> Comparer { get; }
    Property Value
    Type Description
    IComparer<TAbsolute>
    | Improve this Doc View Source

    IsEnabled

    Gets whether the scheduler is enabled to run work.

    Declaration
    public bool IsEnabled { get; }
    Property Value
    Type Description
    Boolean
    | Improve this Doc View Source

    Now

    Gets the scheduler's notion of current time.

    Declaration
    public DateTimeOffset Now { get; }
    Property Value
    Type Description
    DateTimeOffset

    Methods

    | Improve this Doc View Source

    Add(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.

    | Improve this Doc View Source

    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

    time is negative.

    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).

    | Improve this Doc View Source

    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

    time is in the past.

    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).

    | Improve this Doc View Source

    GetNext()

    Gets the next scheduled item to be executed.

    Declaration
    protected abstract IScheduledItem<TAbsolute> GetNext()
    Returns
    Type Description
    IScheduledItem<TAbsolute>

    The next scheduled item.

    | Improve this Doc View Source

    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.

    | Improve this Doc View Source

    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

    action is null.

    | Improve this Doc View Source

    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

    action is null.

    | Improve this Doc View Source

    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

    action is null.

    | Improve this Doc View Source

    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.

    | Improve this Doc View Source

    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.

    | Improve this Doc View Source

    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

    time is negative.

    | Improve this Doc View Source

    Start()

    Starts the virtual time scheduler.

    Declaration
    public void Start()
    | Improve this Doc View Source

    StartStopwatch()

    Starts a new stopwatch object.

    Declaration
    public IStopwatch StartStopwatch()
    Returns
    Type Description
    IStopwatch

    New stopwatch object; started at the time of the request.

    | Improve this Doc View Source

    Stop()

    Stops the virtual time scheduler.

    Declaration
    public void Stop()
    | Improve this Doc View Source

    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.

    | Improve this Doc View Source

    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 Source

    IServiceProvider.GetService(Type)

    Declaration
    object IServiceProvider.GetService(Type serviceType)
    Parameters
    Type Name Description
    Type serviceType
    Returns
    Type Description
    Object

    Implements

    IScheduler
    System.IServiceProvider
    IStopwatchProvider

    Extension Methods

    VirtualTimeSchedulerExtensions.ScheduleRelative<TAbsolute, TRelative>(VirtualTimeSchedulerBase<TAbsolute, TRelative>, TRelative, Action)
    VirtualTimeSchedulerExtensions.ScheduleAbsolute<TAbsolute, TRelative>(VirtualTimeSchedulerBase<TAbsolute, TRelative>, TAbsolute, Action)
    Scheduler.DisableOptimizations(IScheduler)
    Scheduler.DisableOptimizations(IScheduler, Type[])
    Scheduler.Catch<TException>(IScheduler, Func<TException, Boolean>)
    Scheduler.SchedulePeriodic<TState>(IScheduler, TState, TimeSpan, Func<TState, TState>)
    Scheduler.SchedulePeriodic<TState>(IScheduler, TState, TimeSpan, Action<TState>)
    Scheduler.SchedulePeriodic(IScheduler, TimeSpan, Action)
    Scheduler.StartStopwatch(IScheduler)
    Scheduler.AsLongRunning(IScheduler)
    Scheduler.AsStopwatchProvider(IScheduler)
    Scheduler.AsPeriodic(IScheduler)
    Scheduler.Schedule(IScheduler, Action<Action>)
    Scheduler.Schedule<TState>(IScheduler, TState, Action<TState, Action<TState>>)
    Scheduler.Schedule(IScheduler, TimeSpan, Action<Action<TimeSpan>>)
    Scheduler.Schedule<TState>(IScheduler, TState, TimeSpan, Action<TState, Action<TState, TimeSpan>>)
    Scheduler.Schedule(IScheduler, DateTimeOffset, Action<Action<DateTimeOffset>>)
    Scheduler.Schedule<TState>(IScheduler, TState, DateTimeOffset, Action<TState, Action<TState, DateTimeOffset>>)
    Scheduler.Schedule(IScheduler, Action)
    Scheduler.Schedule(IScheduler, TimeSpan, Action)
    Scheduler.Schedule(IScheduler, DateTimeOffset, Action)
    • Improve this Doc
    • View Source
    In This Article
    Back to top Generated by DocFX