Environment.TickCount 屬性
定義
重要
部分資訊涉及發行前產品,在發行之前可能會有大幅修改。 Microsoft 對此處提供的資訊,不做任何明確或隱含的瑕疵擔保。
取得系統啟動後經過的毫秒數。
public:
static property int TickCount { int get(); };
public static int TickCount { get; }
static member TickCount : int
Public Shared ReadOnly Property TickCount As Integer
屬性值
32 位元帶正負號的整數,包含自上一次電腦啟動後所經過的毫秒時間量。
範例
下列範例示範如何擷取 屬性所 TickCount 傳回值的正範圍。 屬性 TickCount 會在 之間 Int32.MinValue 迴圈,這是負數,每 Int32.MaxValue 49.8 天一次。 此程式碼範例會移除符號位,以產生非負數,其會每隔 24.9 天迴圈一次零到 MaxValue 一次。
// 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 an output similar to the following:
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 an output similar to the following:
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.
open System
let result = Environment.TickCount &&& Int32.MaxValue
printfn $"TickCount: {result}"
// This example produces an output similar to the following:
// 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
End Class
'
'This example produces an output similar to the following:
'
'TickCount: 101931139
'
備註
此屬性的值衍生自系統計時器,並儲存為 32 位帶正負號的整數。 請注意,因為它衍生自系統計時器,所以 屬性的 TickCount 解析度僅限於系統計時器的解析度,這通常介於 10 到 16 毫秒的範圍內。
重要
因為屬性值的值 TickCount 是 32 位帶正負號的整數,所以如果系統持續執行, TickCount 則會從零遞增到 Int32.MaxValue 大約 24.9 天,然後跳至 Int32.MinValue ,這是負數,然後在接下來 24.9 天內遞增回零。 您可以藉由呼叫 Windows GetTickCount 函式來解決此問題,此函式會在大約 49.7 天后重設為零,或呼叫 GetTickCount64 函式。
TickCount 不同于 DateTime.Ticks 屬性,這是自 1/0001/0001 12:00am 起經過的 100 奈秒間隔數目。
DateTime.Now使用 屬性可取得這部電腦上的目前本機日期和時間。