Skip to content

CodeTimerEntry

CodeTimerEntry is the mutable record of one timer's running state: name, quantity, start/stop timestamps, longest/shortest/elapsed durations, and a history of captured CustomTimeSpan instances. Instances are held in CodeTimer's static timer dictionary.

Purpose

  • Track the lifecycle (running/not running) and accumulated statistics of a single named or method-scoped timer.

Context

  • Namespace: SAIF.Framework.CodeTimer
  • Assembly/package: SAIF.Framework.CodeTimer.dll

Public members

Member Signature Purpose
name public string name The hierarchical key/name identifying this timer entry.
quantity public int quantity Number of times this timer has been started; initialized to 1 on construction.
started public DateTime started Timestamp when the entry was first created.
lastStarted public DateTime lastStarted Timestamp of the most recent Start() call.
lastStopped public DateTime lastStopped Timestamp of the most recent Stop() call.
longest public double longest Longest single recorded span, in milliseconds.
shortest public double shortest Shortest single recorded span, in milliseconds (-1 until a span is recorded).
elapsed public double elapsed Cumulative elapsed time across all recorded spans, in milliseconds.
spans public List<CustomTimeSpan> spans History of individual captured CustomTimeSpan instances for this entry.
CodeTimerEntry public CodeTimerEntry(string name) Constructs a new entry, marking it started with quantity = 1.
IsRunning public bool IsRunning() Returns whether the entry is currently in a running state.

Inherited public members

Behavioral notes

  • Start() and Stop()/Stop(bool isFinal) are declared internal, so timer lifecycle control is restricted to within the SAIF.Framework.CodeTimer assembly; only CodeTimer (in the same assembly) can start/stop an entry directly.
  • Calling Start() while already running throws ApplicationException("StopWatch running") (see BR-001).
  • Calling Stop(bool) while not running throws ApplicationException("StopWatch not running") (see BR-002).
  • On Stop(bool isFinal), the entry computes the elapsed span since lastStarted, adds it to cumulative elapsed, updates longest/shortest, and appends a new CustomTimeSpan to spans.
  • A commented-out Stopwatch sw field exists in source but is not active; timing is instead computed from DateTime timestamp differences*.

Constraints and usage notes

  • Instances are only meaningfully constructed and mutated by CodeTimer; external callers can read the public fields but cannot call Start()/Stop() directly since those members are internal.
  • shortest is -1 until the first Stop() call completes, so callers should not treat -1 as a valid duration.

Note: Statements marked with * were inferred from code structure, naming conventions, or contextual evidence where direct confirmation was not available in source artifacts. Statements marked with ** could not be confirmed; treat as unknown until verified.

Sources

  • SAIF.Framework.CodeTimer\SAIF.Framework.CodeTimer\CodeTimerEntry.cs