Skip to content
ConsoleMonster

API Reference

Class

SimulatedClock

Namespace ConsoleMonster.Live
Assembly ConsoleMonster
Modifiers sealed

A run clock the work moves forward, for simulated runs (demos, recordings, replays of logged work, tests). A live session reads it through LiveSessionOptions.Clock (give it SimulatedClock.Read, or SimulatedClock.ToSessionOptions), so the header clock, the summary bar's elapsed time and time left, log and activity times and the run result's duration all follow it. SimulatedClock.Wait moves the clock forward in small steps, sleeping a share of the time set by SimulatedClock.Speed so the screen moves smoothly; at speed 0 it never sleeps, which makes a run as fast as the machine and its frames repeatable. Reading it is safe from any thread; move it forward from one thread at a time (the run's own work), or two waits may each add their last step.

Inheritance

  • Object
  • SimulatedClock

Usage

Explore 1 API references to this type

This type appears in these public API surfaces even when no hand-authored example is attached directly to the page.

Accepted by parameters 1

Examples

SimulatedClock clock = new SimulatedClock(speed: 4);
context.Run(dashboard, run => {
    clock.Wait(2.5); // two and a half seconds on the dashboard's clock, about 0.6 s of real time
    return new RunResult("Done");
}, clock.ToSessionOptions());

Constructors

public SimulatedClock(Double speed = 0) #

Creates a clock at zero.

Parameters

speed System.Double = 0 optionalposition: 0
Simulated seconds per real second while waiting; 0 or less never sleeps.

Methods

Advance 2 overloads
public Void Advance(Double seconds) #
Returns: Void

Moves the clock forward at once, without waiting.

Parameters

seconds System.Double requiredposition: 0
The seconds to add (negative values are ignored).
public Void Advance(TimeSpan time) #
Returns: Void

Moves the clock forward at once, without waiting.

Parameters

time System.TimeSpan requiredposition: 0
The time to add (negative values are ignored).
public Void Hold(Double seconds, CancellationToken cancellationToken = default) #
Returns: Void

Waits real time with the clock standing still (a finished screen that stays a moment); never at speed 0.

Parameters

seconds System.Double requiredposition: 0
The real seconds to wait.
cancellationToken System.Threading.CancellationToken = default optionalposition: 1
Cuts the wait short.
public static LiveSessionOptions op_Implicit(SimulatedClock clock) #
Returns: LiveSessionOptions

Converts the clock to session options whose clock it is (PowerShell passes a clock where a run takes options this way).

Parameters

clock ConsoleMonster.Live.SimulatedClock requiredposition: 0
The clock.
public TimeSpan Read() #
Returns: TimeSpan

The time on the clock: the reader for LiveSessionOptions.Clock.

Returns

The time.

public LiveSessionOptions ToSessionOptions() #
Returns: LiveSessionOptions

Session options whose clock is this one.

Returns

New options.

public override String ToString() #
Returns: String

Returns a string that represents the current object.

Returns

A string that represents the current object.

public Void Wait(Double seconds, CancellationToken cancellationToken = default) #
Returns: Void

Moves the clock forward by a time, sleeping in proportion to SimulatedClock.Speed; see SimulatedClock.WaitUntil.

Parameters

seconds System.Double requiredposition: 0
The simulated seconds to wait.
cancellationToken System.Threading.CancellationToken = default optionalposition: 1
Cuts the sleeps short (the clock still moves); see SimulatedClock.WaitUntil.
public Void WaitUntil(Double seconds, CancellationToken cancellationToken = default) #
Returns: Void

Moves the clock forward to a time, in steps of a quarter of a simulated second, sleeping in proportion to SimulatedClock.Speed. A time already passed returns at once. Once the token is cancelled, or the live session the clock runs in (the running session it first sees) is stopped with Ctrl+C, the clock moves on without sleeping, so the work reaches its next cancellation check, or its end, without delay.

Parameters

seconds System.Double requiredposition: 0
The time on the clock to reach, in seconds.
cancellationToken System.Threading.CancellationToken = default optionalposition: 1
Cuts the sleeps short.

Properties

public Double Speed { get; } #

Simulated seconds per real second while waiting; 0 or less never sleeps.

public TimeSpan Elapsed { get; } #

The time on the clock.

public Double Seconds { get; } #

The time on the clock in seconds.