Environment.TickCount プロパティ

定義

システム起動後のミリ秒単位の経過時間を取得します。

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.MaxValueである と 49.8 日ごとに 1 回の間Int32.MinValueで循環します。 このコード サンプルでは、符号ビットを削除して、0 から 24.9 日ごとに 1 回循環 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 約 24.9 日間は 0 Int32.MaxValue から約 24.9 日間インクリメントされ、負の数である にジャンプ Int32.MinValueし、次の 24.9 日間は 0 に戻ります。 この問題を回避するには、約 49.7 日後に 0 にリセットされる Windows GetTickCount 関数を呼び出すか、 GetTickCount64 関数を呼び出します。

TickCount は、 プロパティとは DateTime.Ticks 異なります。これは、1/1/0001、午前 12:00 から経過した 100 ナノ秒間隔の数です。

このコンピューターの DateTime.Now 現在のローカルの日付と時刻を取得するには、 プロパティを使用します。

適用対象