Skip to main content

Ticker class

Namespace: Arlecchino.Hosting · Assembly: Arlecchino

Work on a clock, run between frames on the thread that draws, with a repaint asked for afterward. Missed time is not made up for: an action runs at most once per pass.

public sealed class Ticker

Constructors

MemberSummary
Ticker(TimeProvider, Repaint)Creates the ticker.

Properties

MemberSummary
NextDueWhen the next scheduled action is due, or null when nothing is scheduled.

Methods

MemberSummary
After(TimeSpan, Action)Runs an action once, after the delay.
Every(TimeSpan, Action)Runs an action over and over, waiting the interval between runs.
Run(Action<Exception>)Runs whatever is due. Called by the frame loop; a headless host calls it after moving its own clock forward.

Constructors in detail

Ticker(TimeProvider, Repaint)

public Ticker(TimeProvider time, Repaint repaint);

Creates the ticker.

Parameters

NameTypeDescription
timeTimeProviderWhere the current time comes from; a test host supplies its own.
repaintRepaintAsked for a frame after anything runs.

Properties in detail

NextDue

public Nullable<DateTimeOffset> NextDue { get; }

When the next scheduled action is due, or null when nothing is scheduled.

Type Nullable<T><DateTimeOffset>

Methods in detail

After(TimeSpan, Action)

public IDisposable After(TimeSpan delay, Action action);

Runs an action once, after the delay.

Parameters

NameTypeDescription
delayTimeSpanHow long to wait; anything below a millisecond is raised to one.
actionActionWhat to run.

Returns IDisposable — Dispose it to cancel before it runs.

Every(TimeSpan, Action)

public IDisposable Every(TimeSpan interval, Action action);

Runs an action over and over, waiting the interval between runs.

Parameters

NameTypeDescription
intervalTimeSpanHow long to wait each time; anything below a millisecond is raised to one.
actionActionWhat to run.

Returns IDisposable — Dispose it to stop.

Run(Action<Exception>)

public void Run(Action<Exception> onError);

Runs whatever is due. Called by the frame loop; a headless host calls it after moving its own clock forward.

Parameters

NameTypeDescription
onErrorAction<T><Exception>What to do with an action that threw; the rest still run.