Stopwatch.Frequency 欄位

定義

取得計時器頻率,做為每秒的刻度數。Gets the frequency of the timer as the number of ticks per second. 此欄位為唯讀。This field is read-only.

public: static initonly long Frequency;
public static readonly long Frequency;
 staticval mutable Frequency : int64
Public Shared ReadOnly Frequency As Long 

欄位值

Int64

範例

下列範例會顯示計時器的頻率和解析度 StopwatchThe following example displays the frequency and resolution of a Stopwatch timer. 這個程式碼範例是針對類別提供之較大範例的一部分 StopwatchThis code example is part of a larger example provided for the Stopwatch class.

void DisplayTimerProperties()
{
   // Display the timer frequency and resolution.
   if ( Stopwatch::IsHighResolution )
   {
      Console::WriteLine( "Operations timed using the system's high-resolution performance counter." );
   }
   else
   {
      Console::WriteLine( "Operations timed using the DateTime class." );
   }

   Int64 frequency = Stopwatch::Frequency;
   Console::WriteLine( "  Timer frequency in ticks per second = {0}", frequency );
   Int64 nanosecPerTick = (1000L * 1000L * 1000L) / frequency;
   Console::WriteLine( "  Timer is accurate within {0} nanoseconds", nanosecPerTick );
}
public static void DisplayTimerProperties()
{
    // Display the timer frequency and resolution.
    if (Stopwatch.IsHighResolution)
    {
        Console.WriteLine("Operations timed using the system's high-resolution performance counter.");
    }
    else
    {
        Console.WriteLine("Operations timed using the DateTime class.");
    }

    long frequency = Stopwatch.Frequency;
    Console.WriteLine("  Timer frequency in ticks per second = {0}",
        frequency);
    long nanosecPerTick = (1000L*1000L*1000L) / frequency;
    Console.WriteLine("  Timer is accurate within {0} nanoseconds",
        nanosecPerTick);
}
Public Shared Sub DisplayTimerProperties()

   ' Display the timer frequency and resolution.
   If Stopwatch.IsHighResolution Then
      Console.WriteLine("Operations timed using the system's high-resolution performance counter.")
   Else
      Console.WriteLine("Operations timed using the DateTime class.")
   End If
   
   Dim frequency As Long = Stopwatch.Frequency
   Console.WriteLine("  Timer frequency in ticks per second = {0}", frequency)
   Dim nanosecPerTick As Long = 1000000000 / frequency
   Console.WriteLine("  Timer is accurate within {0} nanoseconds", nanosecPerTick)

End Sub

備註

計時器頻率表示計時器精確度和解析度。The timer frequency indicates the timer precision and resolution. 例如,每秒2000000刻度的計時器頻率等於計時器解析度(每個刻度500毫微秒)。For example, a timer frequency of 2 million ticks per second equals a timer resolution of 500 nanoseconds per tick. 換句話說,因為一秒等於1000000000毫微秒,所以每秒2000000刻度的計時器頻率相當於每1000000000毫微秒的2000000滴答,可進一步簡化為每個500毫微秒1個刻度。In other words, because one second equals 1 billion nanoseconds, a timer frequency of 2 million ticks per second is equivalent to 2 million ticks per 1 billion nanoseconds, which can be further simplified to 1 tick per 500 nanoseconds.

Frequency 值取決於基礎計時機制的解析度。The Frequency value depends on the resolution of the underlying timing mechanism. 如果安裝的硬體和作業系統支援高解析度的效能計數器,則 Frequency 值會反映該計數器的頻率。If the installed hardware and operating system support a high-resolution performance counter, then the Frequency value reflects the frequency of that counter. 否則,此 Frequency 值會以系統計時器頻率為基礎。Otherwise, the Frequency value is based on the system timer frequency.

因為 Stopwatch 頻率取決於已安裝的硬體和作業系統,所以 Frequency 當系統正在執行時,值會維持不變。Because the Stopwatch frequency depends on the installed hardware and operating system, the Frequency value remains constant while the system is running.

適用於

另請參閱