Stopwatch.Frequency Bidang

Definisi

Mendapatkan frekuensi timer sebagai jumlah tick per detik. Bidang ini hanya-baca.

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

Nilai Bidang

Contoh

Contoh berikut menampilkan frekuensi dan resolusi Stopwatch timer. Contoh kode ini adalah bagian dari contoh yang lebih besar yang disediakan untuk Stopwatch kelas .

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

Keterangan

Frekuensi timer menunjukkan presisi dan resolusi timer. Misalnya, frekuensi timer 2 juta tick per detik sama dengan resolusi timer 500 nanodetik per tick. Dengan kata lain, karena satu detik sama dengan 1 miliar nanodetik, frekuensi timer 2 juta kutu per detik setara dengan 2 juta kutu per 1 miliar nanodetik, yang dapat disederhanakan lebih lanjut menjadi 1 tick per 500 nanodetik.

Nilai Frequency tergantung pada resolusi mekanisme pengaturan waktu yang mendasar. Jika perangkat keras dan sistem operasi yang diinstal mendukung penghitung kinerja resolusi tinggi, maka Frequency nilainya mencerminkan frekuensi penghitung tersebut. Jika tidak, Frequency nilai didasarkan pada frekuensi timer sistem.

Stopwatch Karena frekuensi tergantung pada perangkat keras dan sistem operasi yang diinstal, nilainya Frequency tetap konstan saat sistem berjalan.

Berlaku untuk

Lihat juga