共用方式為


Stopwatch.IsHighResolution 欄位

定義

指示計時器是否以高解析度效能計數器為基礎。 此欄位為唯讀。

public: static initonly bool IsHighResolution;
public static readonly bool IsHighResolution;
 staticval mutable IsHighResolution : bool
Public Shared ReadOnly IsHighResolution As Boolean 

欄位值

範例

下列範例會顯示定時器的頻率和解析度 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

備註

類別所使用的 Stopwatch 定時器取決於系統硬體和操作系統。 IsHighResolution如果trueStopwatch定時器是以高解析度效能計數器為基礎,則為 。 否則為 IsHighResolutionfalse,表示 Stopwatch 定時器是以系統定時器為基礎。

適用於

另請參閱