Stopwatch.Frequency 欄位
定義
重要
部分資訊涉及發行前產品,在發行之前可能會有大幅修改。 Microsoft 對此處提供的資訊,不做任何明確或隱含的瑕疵擔保。
取得計時器頻率,做為每秒的刻度數。 此欄位為唯讀。
public: static initonly long Frequency;
public static readonly long Frequency;
staticval mutable Frequency : int64
Public Shared ReadOnly Frequency As Long
欄位值
範例
下列範例會顯示定時器的頻率和解析度 Stopwatch 。 此程式代碼範例是提供給 類別之較大範例的 Stopwatch 一部分。
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
備註
定時器頻率表示定時器精確度和解析度。 例如,每秒 2 百萬個刻度定時器頻率等於每個刻度 500 奈秒的定時器解析度。 換句話說,因為一秒等於10億奈秒,每秒2百萬個刻度數的定時器頻率相當於每10億奈秒2百萬個刻度,這可進一步簡化為每500奈秒1個刻度。
值 Frequency 取決於基礎計時機制的解析。 如果已安裝的硬體和操作系統支援高解析度性能計數器,則 Frequency 此值會反映該計數器的頻率。 否則,此值 Frequency 會以系統定時器頻率為基礎。
Stopwatch因為頻率取決於已安裝的硬體和操作系統,所以當系統執行時,Frequency該值會維持不變。