Early Preview

This is currently very much a preview. Please feel free to try things out, but don't be upset if anything is not yet working. Feedback is welcome over on our GitHub Dicussions page.

class System.​Diagnostics.​Stopwatch

Assembly: System.Runtime

Inheritance: object → Stopwatch

Provides a set of methods and properties that you can use to accurately measure elapsed time.

Fields and Constants

public static readonly long
Frequency
Gets the frequency of the timer as the number of ticks per second. This field is read-only.
public static readonly bool
IsHighResolution
Indicates whether the timer is based on a high-resolution performance counter. This field is read-only.

Properties

public TimeSpan
Elapsed
Gets the total elapsed time measured by the current instance.
public long
ElapsedMilliseconds
Gets the total elapsed time measured by the current instance, in milliseconds.
public long
ElapsedTicks
Gets the total elapsed time measured by the current instance, in timer ticks.
public bool
IsRunning
Gets a value indicating whether the <see cref="T:System.Diagnostics.Stopwatch" /> timer is running.

Methods

public static TimeSpan
GetElapsedTime​(long startingTimestamp)
Gets the elapsed time since the <paramref name="startingTimestamp" /> value retrieved using <see cref="M:System.Diagnostics.Stopwatch.GetTimestamp" /> .
Returns A <see cref="T:System.TimeSpan" /> for the elapsed time between the starting timestamp and the time of this call.
startingTimestamp The timestamp marking the beginning of the time period.
public static TimeSpan
GetElapsedTime​(long startingTimestamp, long endingTimestamp)
Gets the elapsed time between two timestamps retrieved using <see cref="M:System.Diagnostics.Stopwatch.GetTimestamp" /> .
Returns A <see cref="T:System.TimeSpan" /> for the elapsed time between the starting and ending timestamps.
startingTimestamp The timestamp marking the beginning of the time period.
endingTimestamp The timestamp marking the end of the time period.
public static long
GetTimestamp​()
Gets the current number of ticks in the timer mechanism.
Returns A long integer representing the tick counter value of the underlying timer mechanism.
public void
Reset​()
Stops time interval measurement and resets the elapsed time to zero.
public void
Restart​()
Stops time interval measurement, resets the elapsed time to zero, and starts measuring elapsed time.
public void
Start​()
Starts, or resumes, measuring elapsed time for an interval.
public static Stopwatch
StartNew​()
Initializes a new <see cref="T:System.Diagnostics.Stopwatch" /> instance, sets the elapsed time property to zero, and starts measuring elapsed time.
Returns A <see cref="T:System.Diagnostics.Stopwatch" /> that has just begun measuring elapsed time.
public void
Stop​()
Stops measuring elapsed time for an interval.
public string
ToString​()
Returns the <see cref="P:System.Diagnostics.Stopwatch.Elapsed" /> time as a string.
Returns The elapsed time string in the same format used by <see cref="M:System.TimeSpan.ToString" /> .
public bool
Equals​(object obj)
Inherited from object
Determines whether the specified object is equal to the current object.
Returns <see langword="true" /> if the specified object is equal to the current object; otherwise, <see langword="false" /> .
obj The object to compare with the current object.
protected void
Finalize​()
Inherited from object
Allows an object to try to free resources and perform other cleanup operations before it is reclaimed by garbage collection.
public int
GetHashCode​()
Inherited from object
Serves as the default hash function.
Returns A hash code for the current object.
public Type
GetType​()
Inherited from object
Gets the <see cref="T:System.Type" /> of the current instance.
Returns The exact runtime type of the current instance.
protected object
MemberwiseClone​()
Inherited from object
Creates a shallow copy of the current <see cref="T:System.Object" /> .
Returns A shallow copy of the current <see cref="T:System.Object" /> .