Export (0) Print
Expand All

Stopwatch.IsHighResolution Field

Indicates whether the timer is based on a high-resolution performance counter. This field is read-only.

Namespace: System.Diagnostics
Assembly: System (in system.dll)

public:
static initonly bool IsHighResolution
public static final boolean IsHighResolution
public static final var IsHighResolution : boolean
Not applicable.

The timer used by the Stopwatch class depends on the system hardware and operating system. IsHighResolution is true if the Stopwatch timer is based on a high-resolution performance counter. Otherwise, IsHighResolution is false, which indicates that the Stopwatch timer is based on the system timer.

The following example displays the frequency and resolution of 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}", 
        (Int64)frequency);
    long nanoSecPerTick = (1000L * 1000L * 1000L) / frequency;
    Console.WriteLine("  Timer is accurate within {0} nanoseconds", 
        (Int64)nanoSecPerTick);
} //DisplayTimerProperties

Windows 98, Windows Server 2000 SP4, Windows Millennium Edition, Windows Server 2003, Windows XP Media Center Edition, Windows XP Professional x64 Edition, Windows XP SP2, Windows XP Starter Edition

The Microsoft .NET Framework 3.0 is supported on Windows Vista, Microsoft Windows XP SP2, and Windows Server 2003 SP1.

.NET Framework

Supported in: 3.0, 2.0

XNA Framework

Supported in: 1.0

Community Additions

ADD
Show:
© 2014 Microsoft