API Reference
SimulatedClock
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 System.Double = 0
- Simulated seconds per real second while waiting; 0 or less never sleeps.
Methods
public Void Advance(Double seconds) #VoidMoves the clock forward at once, without waiting.
Parameters
- seconds System.Double
- The seconds to add (negative values are ignored).
public Void Advance(TimeSpan time) #VoidMoves 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) #VoidWaits real time with the clock standing still (a finished screen that stays a moment); never at speed 0.
Parameters
- seconds System.Double
- The real seconds to wait.
- cancellationToken System.Threading.CancellationToken = default
- Cuts the wait short.
public static LiveSessionOptions op_Implicit(SimulatedClock clock) #LiveSessionOptionsConverts 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.
public TimeSpan Read() #TimeSpanThe time on the clock: the reader for LiveSessionOptions.Clock.
Returns
The time.
public LiveSessionOptions ToSessionOptions() #LiveSessionOptionsSession options whose clock is this one.
Returns
New options.
public override String ToString() #StringReturns a string that represents the current object.
Returns
A string that represents the current object.
public Void Wait(Double seconds, CancellationToken cancellationToken = default) #VoidMoves the clock forward by a time, sleeping in proportion to SimulatedClock.Speed; see SimulatedClock.WaitUntil.
Parameters
- seconds System.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) #VoidMoves 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
- 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.