Skip to content

XUIStopWatch

Description

A class for measuring elapsed time.

Properties

Name Type Read-Only
IsRunning Boolean
mEnd DateTime
mIsRunning Boolean
mStart DateTime

Methods

Name Parameters Returns
Constructor startImmediately As Boolean
Elapsed DateInterval
ElapsedAsString String
ElapsedMilliseconds Integer
ElapsedSeconds Integer
ElapsedTicks Integer
Reset
Start
Stop

Constants

Name Type
MS_IN_DAY Double
MS_IN_HOUR Double
MS_IN_MIN Double
MS_IN_SEC Double
MS_IN_WEEK Double
NS_IN_MS Double
NS_IN_TICK Double
SECS_IN_DAY Double
SECS_IN_HOUR Double
TICKS_IN_DAY Double
TICKS_IN_HOUR Double
TICKS_IN_MIN Double
TICKS_IN_SEC Double

MS_IN_DAY As Double The number of milliseconds in a day.


MS_IN_HOUR As Double The number of milliseconds in an hour.


MS_IN_MIN As Double The number of milliseconds in a minute.


MS_IN_SEC As Double The number of milliseconds in a second.


MS_IN_WEEK As Double The number of milliseconds in a week.


NS_IN_MS As Double The number of nanoseconds in a millisecond.


NS_IN_TICK As Double The number of nanoseconds in a tick.


SECS_IN_DAY As Double The number of seconds in a day.


SECS_IN_HOUR As Double The number of seconds in an hour.


TICKS_IN_DAY As Double The number of ticks in a day.


TICKS_IN_HOUR As Double The number of ticks in an hour.


TICKS_IN_MIN As Double The number of ticks in a minute.


TICKS_IN_SEC As Double The number of ticks in a second.


Property Descriptions

IsRunning As Boolean

True if the stopwatch is currently running.


mEnd As DateTime

The exact moment the stopwatch ended.


mIsRunning As Boolean

Backing field for the IsRunning computed property.


mStart As DateTime

The exact moment the stopwatch started running.


Method Descriptions

Constructor(startImmediately As Boolean)

If startImmediately is True then the stopwatch will start upon instantiation.


Elapsed() As DateInterval

A read-only DateInterval representing the total elapsed time measured by the current instance.


ElapsedAsString() As String

Returns a string representation of the elapsed interval.


ElapsedMilliseconds() As Integer

The total elapsed time measured by the current instance, in milliseconds.

If the stopwatch has been running for > 28 days then an UnsupportedOperationException is raised.


ElapsedSeconds() As Integer

The total elapsed time measured by the current instance, in seconds.

If the stopwatch has been running for > 28 days then an UnsupportedOperationException is raised.


ElapsedTicks() As Integer

The total elapsed time measured by the current instance, in ticks.

If the stopwatch has been running for > 28 days then an UnsupportedOperationException is raised.


Reset()

Resets all internal properties.


Start()

Begins timing.


Stop()

Stops timing.


Example

Var watch As New StopWatch
watch.Start
// Do something that you want to time...
watch.Stop

// Easy access to watch properties:
Var ms As Double = watch.ElapsedMilliseconds
Var t As Double = watch.ElapsedTicks
Var di As DateInterval = watch.Elapsed

// StopWatch will even format the interval into a string:
Var s As String = watch.ElapsedAsString // E.g "4 minutes, 3 seconds, 89 ms"

// Query if the stopwatch is running:
If watch.IsRunning Then
// Do something
End If

// You can call `ElapsedTicks`, etc whilst the stopwatch is running too.