Environment.TickCount Environment.TickCount Environment.TickCount Environment.TickCount Property

定义

获取系统启动后经过的毫秒数。Gets the number of milliseconds elapsed since the system started.

public:
 static property int TickCount { int get(); };
public static int TickCount { get; }
member this.TickCount : int
Public Shared ReadOnly Property TickCount As Integer

属性值

一个 32 位带符号整数,它包含自上次启动计算机以来所经过的时间(以毫秒为单位)。A 32-bit signed integer containing the amount of time in milliseconds that has passed since the last time the computer was started.

示例

下面的示例演示如何检索返回值的正值范围TickCount属性。The following example demonstrates how to retrieve the positive range of values returned by the TickCount property. TickCount属性之间循环Int32.MinValue,这是负数,和Int32.MaxValue49.8 天一次。The TickCount property cycles between Int32.MinValue, which is a negative number, and Int32.MaxValue once every 49.8 days. 此代码示例会删除符号位,以生成一个非负数字,周期介于零和MaxValue24.9 天。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
*/
// 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
*/

' 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
'

注解

此属性的值派生自系统计时器,并存储为 32 位有符号整数。The value of this property is derived from the system timer and is stored as a 32-bit signed integer. 注意,因为它派生自系统计时器的分辨率TickCount属性仅限于系统计时器,它通常在 10 到 16 毫秒为单位的范围的解决方法。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.

重要

因为的值TickCount属性值是 32 位带符号的整数,如果系统连续,运行TickCount从零到将递增Int32.MaxValue大约 24.9 天,然后跳转到Int32.MinValue,这是负号,然后递增到下一步 24.9 几天的零。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. 可以通过调用 Windows 来解决此问题GetTickCount函数,它将重置为零大约 49.7 天,或通过调用GetTickCount64函数。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 不同于DateTime.Ticks属性,它是 0001 年 1 月 1 日,12:00 am 起经过的 100 纳秒间隔数。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.

使用DateTime.Now属性来获取当前本地日期和时间在此计算机上的。Use the DateTime.Now property to obtain the current local date and time on this computer.

适用于