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

Definición

Obtiene el número de milisegundos transcurridos desde que se inició el sistema.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

Valor de propiedad

Un entero de 32 bits que contiene el tiempo en milisegundos que transcurrió desde la última vez que se inició el equipo.A 32-bit signed integer containing the amount of time in milliseconds that has passed since the last time the computer was started.

Ejemplos

En el ejemplo siguiente se muestra cómo recuperar el intervalo positivo de los valores devueltos por la TickCount propiedad.The following example demonstrates how to retrieve the positive range of values returned by the TickCount property. La TickCount propiedad se desplaza Int32.MinValueentre, que es un número negativo, Int32.MaxValue y una vez cada 49,8 días.The TickCount property cycles between Int32.MinValue, which is a negative number, and Int32.MaxValue once every 49.8 days. En este ejemplo de código se quita el bit de signo para producir un número no negativo que MaxValue se repite entre cero y una vez cada 24,9 días.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.

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
'

Comentarios

El valor de esta propiedad se deriva del temporizador del sistema y se almacena como un entero con signo de 32 bits.The value of this property is derived from the system timer and is stored as a 32-bit signed integer. Tenga en cuenta que, dado que se deriva del temporizador del sistema, la resolución TickCount de la propiedad está limitada a la resolución del temporizador del sistema, que normalmente se encuentra en el intervalo de 10 a 16 milisegundos.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.

Importante

Dado que el valor del TickCount valor de propiedad es un entero con signo de 32 bits, si el sistema se ejecuta TickCount de forma continua, se Int32.MaxValue incrementará desde cero hasta aproximadamente 24,9 días Int32.MinValuey, a continuación, saltará a, que es un número negativo. después, vuelva a cero durante los próximos 24,9 días.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. Para solucionar este problema, puede llamar a la función GetTickCount de Windows, que se restablece a cero después de aproximadamente 49,7 días o llamando a la función 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.

TickCountes diferente de la DateTime.Ticks propiedad, que es el número de intervalos de 100 nanosegundos que han transcurrido desde 1/1/0001, 12: a.m.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.

Utilice la DateTime.Now propiedad para obtener la fecha y hora locales actuales de este equipo.Use the DateTime.Now property to obtain the current local date and time on this computer.

Se aplica a