Stopwatch.IsHighResolution Fält
Definition
Viktigt
En del information gäller för förhandsversionen av en produkt och kan komma att ändras avsevärt innan produkten blir allmänt tillgänglig. Microsoft lämnar inga garantier, uttryckliga eller underförstådda, avseende informationen som visas här.
Anger om timern baseras på en prestandaräknare med hög upplösning. Detta fält är skrivskyddat.
public: static initonly bool IsHighResolution;
public static readonly bool IsHighResolution;
staticval mutable IsHighResolution : bool
Public Shared ReadOnly IsHighResolution As Boolean
Fältvärde
Exempel
I följande exempel visas frekvensen och upplösningen för en Stopwatch timer. Det här kodexemplet är en del av ett större exempel för Stopwatch klassen.
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
Kommentarer
Vilken timer som används av Stopwatch klassen beror på systemets maskinvara och operativsystem.
IsHighResolution är true om Stopwatch timern baseras på en prestandaräknare med hög upplösning. Annars IsHighResolution är false, vilket indikerar att Stopwatch timern baseras på systemtimern.