Click to Rate and Give Feedback
MSDN
MSDN Library
.NET Development
.NET Framework 4
System
Environment Class
 TickCount Property
Collapse All/Expand All Collapse All
.NET Framework Class Library
Environment..::.TickCount Property

Gets the number of milliseconds elapsed since the system started.

Namespace:  System
Assembly:  mscorlib (in mscorlib.dll)
Visual Basic
Public Shared ReadOnly Property TickCount As Integer
C#
public static int TickCount { get; }
Visual C++
public:
static property int TickCount {
    int get ();
}
F#
static member TickCount : int

Property Value

Type: System..::.Int32
A 32-bit signed integer containing the amount of time in milliseconds that has passed since the last time the computer was started.

The value of this property is derived from the system timer and is stored as a 32-bit signed integer. Consequently, if the system runs continuously, TickCount will increment from zero to Int32..::.MaxValue for approximately 24.9 days, then jump to Int32..::.MinValue, which is a negative number, then increment back to zero during the next 24.9 days.

TickCount is different from the Ticks property, which is the number of 100-nanosecond intervals that have elapsed since 1/1/0001, 12:00am.

Use the DateTime..::.Now property to obtain the current local date and time on this computer.

The following example demonstrates how to retrieve the positive range of values returned by the TickCount property. The TickCount property cycles between Int32..::.MinValue, which is a negative number, and Int32..::.MaxValue once every 49.8 days. This code sample removes the sign bit to yield a nonnegative number that cycles between zero and MaxValue once every 24.9 days.

Visual Basic

' Sample for the Environment.TickCount property.
' TickCount cycles between Int32.MinValue, which is a negative 
' number, and Int32.MaxValue once every 49.8 days. This sample
' removes the sign bit to yield a nonnegative number that cycles 
' between zero and Int32.MaxValue once every 24.9 days.

Imports System

Class Sample
   Public Shared Sub Main()
      Dim result As Integer = Environment.TickCount And Int32.MaxValue

      Console.WriteLine("TickCount: {0}", result)
   End Sub 'Main
End Class 'Sample
'
'This example produces the following results:
'
'TickCount: 101931139
'
C#
// Sample for the Environment.TickCount property.

// TickCount cycles between Int32.MinValue, which is a negative 
// number, and Int32.MaxValue once every 49.8 days. This sample
// removes the sign bit to yield a nonnegative number that cycles 
// between zero and Int32.MaxValue once every 24.9 days.

using System;

class Sample 
{
    public static void Main() 
    {
    int result = Environment.TickCount & Int32.MaxValue;
    Console.WriteLine("TickCount: {0}", result);
    }
}
/*
This example produces the following results:

TickCount: 101931139
*/
Visual C++
// Sample for the Environment::TickCount property
// TickCount cycles between Int32::MinValue, which is a negative 
// number, and Int32::MaxValue once every 49.8 days. This sample
// removes the sign bit to yield a nonnegative number that cycles 
// between zero and Int32::MaxValue once every 24.9 days.
using namespace System;
int main()
{
   int result = Environment::TickCount & Int32::MaxValue;
   Console::WriteLine( "TickCount: {0}", result );
}

/*
This example produces the following results:

TickCount: 101931139
*/

.NET Framework

Supported in: 4, 3.5, 3.0, 2.0, 1.1, 1.0

.NET Framework Client Profile

Supported in: 4, 3.5 SP1

Portable Class Library

Supported in: Portable Class Library

Windows 7, Windows Vista SP1 or later, Windows XP SP3, Windows XP SP2 x64 Edition, Windows Server 2008 (Server Core not supported), Windows Server 2008 R2 (Server Core supported with SP1 or later), Windows Server 2003 SP2

The .NET Framework does not support all versions of every platform. For a list of the supported versions, see .NET Framework System Requirements.
Tags What's this?: Add a tag
Community Content   What is Community Content?
Add new content RSS  Annotations
Accuracy Please      TheToid   |   Edit   |   Show History
This article should contain the accuracy of the TickCount property? What is the accuracy?
Tags What's this?: Add a tag
Flag as ContentBug
Processing
© 2012 Microsoft. All rights reserved. Terms of Use | Trademarks | Privacy Statement
Page view tracker