Export (0) Print
Expand All

Stopwatch.IsRunning Property

Note: This property is new in the .NET Framework version 2.0.

Gets a value indicating whether the Stopwatch timer is running.

Namespace: System.Diagnostics
Assembly: System (in system.dll)

public bool IsRunning { get; }
/** @property */
public boolean get_IsRunning ()

public function get IsRunning () : boolean

Property Value

true if the Stopwatch instance is currently running and measuring elapsed time for an interval; otherwise, false.

A Stopwatch instance begins running with a call to Start or StartNew. The instance stops running with a call to Stop or Reset.

The following example uses the Stopwatch class to implement start, stop, reset, and lap-time buttons in a Windows form application. This code example is part of a larger example provided for the Stopwatch class.

if (stopWatch.IsRunning)
{
    // Stop the timer; show the start and reset buttons.
    stopWatch.Stop();
    buttonStartStop.Text = "Start";
    buttonLapReset.Text = "Reset";
}
else 
{
    // Start the timer; show the stop and lap buttons.
    stopWatch.Start();
    buttonStartStop.Text = "Stop";
    buttonLapReset.Text = "Lap";
    labelLap.Visible = false;
    labelLapPrompt.Visible = false;
}

if (stopWatch.get_IsRunning()) {
    // Stop the timer; show the start and reset buttons.
    stopWatch.Stop();
    buttonStartStop.set_Text("Start");
    buttonLapReset.set_Text("Reset");
}
else {
    // Start the timer; show the stop and lap buttons.
    stopWatch.Start();
    buttonStartStop.set_Text("Stop");
    buttonLapReset.set_Text("Lap");
    labelLap.set_Visible(false);
    labelLapPrompt.set_Visible(false);
}

Windows 98, Windows 2000 SP4, Windows Millennium Edition, Windows Server 2003, Windows XP Media Center Edition, Windows XP Professional x64 Edition, Windows XP SP2, Windows XP Starter Edition

The .NET Framework does not support all versions of every platform. For a list of the supported versions, see System Requirements.

.NET Framework

Supported in: 2.0

Community Additions

ADD
Show:
© 2014 Microsoft