Was this page helpful?
Your feedback about this content is important. Let us know what you think.
Additional feedback?
1500 characters remaining
TickCount Property

Environment::TickCount Property

Gets the number of milliseconds elapsed since the system started.

Namespace:  System
Assemblies:   mscorlib (in mscorlib.dll)
  System.Runtime.Extensions (in System.Runtime.Extensions.dll)

public:
static property int TickCount {
	int get ();
}

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. Note that, because it is derived from the system timer, the resolution of the TickCount property is limited to the resolution of the system timer, which is typically in the range of 10 to 16 milliseconds.

Important noteImportant

Because the value of the TickCount property value is a 32-bit signed integer, 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. You can work around this issue by calling the Windows GetTickCount function, which resets to zero after approximately 49.7 days, or by calling the GetTickCount64 function.

TickCount is different from the DateTime::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.

// 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.6, 4.5, 4, 3.5, 3.0, 2.0, 1.1

.NET Framework Client Profile

Supported in: 4, 3.5 SP1

XNA Framework

Supported in: 3.0, 2.0, 1.0

.NET for Windows Phone apps

Supported in: Windows Phone 8.1, Windows Phone Silverlight 8.1, Windows Phone Silverlight 8

Portable Class Library

Supported in: Portable Class Library
Show:
© 2015 Microsoft