SimulatedClock
ConsoleMonster.Live
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
- Method SimulatedClock.op_Implicit
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 double = 0
- Simulated seconds per real second while waiting; 0 or less never sleeps.
Methods
public void Advance(double seconds) #Moves the clock forward at once, without waiting.
Parameters
- seconds double
- The seconds to add (negative values are ignored).
public void Advance(TimeSpan time) #Moves the clock forward at once, without waiting.
Parameters
- time System.TimeSpan
- The time to add (negative values are ignored).
public void Hold(double seconds, CancellationToken cancellationToken = default) #Waits real time with the clock standing still (a finished screen that stays a moment); never at speed 0. A full-viewport target with skipped delays captures a final checkpoint instead, including a zero-duration hold.
Parameters
- seconds double
- The real seconds to wait.
- cancellationToken System.Threading.CancellationToken = default
- Cuts the wait short.
public static LiveSessionOptions op_Implicit(SimulatedClock clock) #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
- The clock.
Returns
LiveSessionOptionspublic TimeSpan Read() #The time on the clock: the reader for LiveSessionOptions.Clock.
Returns
TimeSpan The time.public LiveSessionOptions ToSessionOptions() #Session options whose clock is this one.
public override string ToString() #Returns a string that represents the current object.
Returns
string A string that represents the current object.public void Wait(double seconds, CancellationToken cancellationToken = default) #Moves the clock forward by a time, sleeping in proportion to SimulatedClock.Speed; see SimulatedClock.WaitUntil.
Parameters
- seconds double
- The simulated seconds to wait.
- cancellationToken System.Threading.CancellationToken = default
- Cuts the sleeps short (the clock still moves); see SimulatedClock.WaitUntil.
public void WaitUntil(double seconds, CancellationToken cancellationToken = default) #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. A full-viewport recording target with skipped delays captures each simulated step after queued updates, without real-time sampling or sleeping.
Parameters
- seconds double
- The time on the clock to reach, in seconds.
- cancellationToken System.Threading.CancellationToken = default
- Cuts the sleeps short.
Inherited Methods
Properties
public double Speed { get; } #Simulated seconds per real second while waiting; 0 or less never sleeps.