Table of Contents

Class TimedEvents

Namespace
Terminal.Gui.App
Assembly
Terminal.Gui.dll

Manages scheduled timeouts (timed callbacks) for the application.

Allows scheduling of callbacks to be invoked after a specified delay, with optional repetition. Timeouts are stored in a sorted list by their scheduled execution time (high-resolution ticks). Thread-safe for concurrent access.

Typical usage:

  1. Call Add(TimeSpan, Func<bool>) to schedule a callback.
  2. Call RunTimers() periodically (e.g., from the main loop) to execute due callbacks.
  3. Call Remove(object) to cancel a scheduled timeout.
public class TimedEvents : ITimedEvents
Inheritance
TimedEvents
Implements
Inherited Members

Remarks

By default, uses GetTimestamp() for high-resolution timing to provide microsecond-level precision and eliminate race conditions from timer resolution issues.

For testing scenarios, an ITimeProvider can be injected via the constructor to enable virtual time control, allowing tests to run instantly without real delays.

Constructors

TimedEvents()

Initializes a new instance of TimedEvents with the default system time provider.

TimedEvents(ITimeProvider?)

Initializes a new instance of TimedEvents with the specified time provider.

Properties

Timeouts

Gets the list of all timeouts sorted by the TimeSpan time ticks. A shorter limit time can be added at the end, but it will be called before an earlier addition that has a longer limit time.

Methods

Add(TimeSpan, Func<bool>)

Adds a timeout to the application.

Add(Timeout)

Adds a timeout to the application.

CheckTimers(out int)
GetTimeout(object)

Gets the timeout for the specified event.

Remove(object)

Removes a previously scheduled timeout.

RunTimers()

Runs all timeouts that are due.

StopAll()

Stops and removes all timed events.

Events

Added

Invoked when a new timeout is added. To be used in the case when StopAfterFirstIteration is true.