Click to Rate and Give Feedback
MSDN
MSDN Library
.NET Development
.NET Framework 3.5
Stopwatch Class
 Stopwatch Constructor
This page is specific to
Microsoft Visual Studio 2008/.NET Framework 3.5

Other versions are also available for the following:
.NET Framework Class Library
Stopwatch Constructor

Updated: November 2007

Initializes a new instance of the Stopwatch class.

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

Visual Basic (Declaration)
Public Sub New
Visual Basic (Usage)
Dim instance As New Stopwatch()
C#
public Stopwatch()
Visual C++
public:
Stopwatch()
J#
public Stopwatch()
JScript
public function Stopwatch()

The returned Stopwatch instance is stopped, and the elapsed time property of the instance is zero.

Use the Start method to begin measuring elapsed time with the new Stopwatch instance. Use the StartNew method to initialize a new Stopwatch instance and immediately start it.

The following example initializes a Stopwatch instance within a simple class constructor. This code example is part of a larger example provided for the Stopwatch class.

Visual Basic
Dim stopWatch As StopWatch
Dim captureLap As Boolean

Public Sub New()

    MyBase.New()
    stopwatch = New StopWatch()
    captureLap = False
    InitializeComponent()

End Sub

C#
private Stopwatch stopWatch;
private Boolean captureLap;

public FormMain()
{
    stopWatch = new Stopwatch();
    captureLap = false;

    InitializeComponent();
}

Visual C++
private:
   Stopwatch^ stopWatch;
   Boolean captureLap;

public:
   FormMain()
   {
      stopWatch = gcnew Stopwatch;
      captureLap = false;
      InitializeComponent();
   }

J#
private Stopwatch stopWatch;
private Boolean captureLap;

public FormMain()
{
    stopWatch = new Stopwatch();
    captureLap = new Boolean(false);

    InitializeComponent();
} //FormMain

Windows Vista, Windows XP SP2, Windows XP Media Center Edition, Windows XP Professional x64 Edition, Windows XP Starter Edition, Windows Server 2003, Windows Server 2000 SP4, Windows Millennium Edition, Windows 98, Windows CE, Windows Mobile for Smartphone, Windows Mobile for Pocket PC, Xbox 360

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

.NET Framework

Supported in: 3.5, 3.0, 2.0

.NET Compact Framework

Supported in: 3.5

XNA Framework

Supported in: 2.0, 1.0
Tags What's this?: Add a tag
Community Content   What is Community Content?
Add new content RSS  Annotations
Processing
© 2008 Microsoft Corporation. All rights reserved. Terms of Use  |  Trademarks  |  Privacy Statement
Page view tracker