Stopwatch.ElapsedTicks Özellik

Tanım

Süreölçer değerlerinde geçerli örnek tarafından ölçülen toplam süreyi alır.

public:
 property long ElapsedTicks { long get(); };
public long ElapsedTicks { get; }
member this.ElapsedTicks : int64
Public ReadOnly Property ElapsedTicks As Long

Özellik Değeri

Geçerli örnek tarafından ölçülen toplam zamanlayıcı işaretlerinin sayısını temsil eden salt okunur uzun bir tamsayı.

Örnekler

Aşağıdaki örnek, bir dizeden Stopwatch tamsayı ayrıştırmak için dört farklı uygulamanın performansını ölçmek için sınıfını kullanır. Bu kod örneği, sınıfı için Stopwatch sağlanan daha büyük bir örneğin parçasıdır.

long ticksThisTime = 0;
int inputNum;
Stopwatch timePerParse;

switch (operation)
{
    case 0:
        // Parse a valid integer using
        // a try-catch statement.

        // Start a new stopwatch timer.
        timePerParse = Stopwatch.StartNew();

        try
        {
            inputNum = Int32.Parse("0");
        }
        catch (FormatException)
        {
            inputNum = 0;
        }

        // Stop the timer, and save the
        // elapsed ticks for the operation.

        timePerParse.Stop();
        ticksThisTime = timePerParse.ElapsedTicks;
        break;
    case 1:
        // Parse a valid integer using
        // the TryParse statement.

        // Start a new stopwatch timer.
        timePerParse = Stopwatch.StartNew();

        if (!Int32.TryParse("0", out inputNum))
        {
            inputNum = 0;
        }

        // Stop the timer, and save the
        // elapsed ticks for the operation.
        timePerParse.Stop();
        ticksThisTime = timePerParse.ElapsedTicks;
        break;
    case 2:
        // Parse an invalid value using
        // a try-catch statement.

        // Start a new stopwatch timer.
        timePerParse = Stopwatch.StartNew();

        try
        {
            inputNum = Int32.Parse("a");
        }
        catch (FormatException)
        {
            inputNum = 0;
        }

        // Stop the timer, and save the
        // elapsed ticks for the operation.
        timePerParse.Stop();
        ticksThisTime = timePerParse.ElapsedTicks;
        break;
    case 3:
        // Parse an invalid value using
        // the TryParse statement.

        // Start a new stopwatch timer.
        timePerParse = Stopwatch.StartNew();

        if (!Int32.TryParse("a", out inputNum))
        {
            inputNum = 0;
        }

        // Stop the timer, and save the
        // elapsed ticks for the operation.
        timePerParse.Stop();
        ticksThisTime = timePerParse.ElapsedTicks;
        break;

    default:
        break;
}
Dim ticksThisTime As Long = 0
Dim inputNum As Integer
Dim timePerParse As Stopwatch

Select Case operation
   Case 0
      ' Parse a valid integer using
      ' a try-catch statement.
      ' Start a new stopwatch timer.
      timePerParse = Stopwatch.StartNew()

      Try
         inputNum = Int32.Parse("0")
      Catch e As FormatException
         inputNum = 0
      End Try

      ' Stop the timer, and save the
      ' elapsed ticks for the operation.
      timePerParse.Stop()
      ticksThisTime = timePerParse.ElapsedTicks
   Case 1
      ' Parse a valid integer using
      ' the TryParse statement.
      ' Start a new stopwatch timer.
      timePerParse = Stopwatch.StartNew()

      If Not Int32.TryParse("0", inputNum) Then
         inputNum = 0
      End If

      ' Stop the timer, and save the
      ' elapsed ticks for the operation.
      timePerParse.Stop()
      ticksThisTime = timePerParse.ElapsedTicks
   Case 2
      ' Parse an invalid value using
      ' a try-catch statement.
      ' Start a new stopwatch timer.
      timePerParse = Stopwatch.StartNew()

      Try
         inputNum = Int32.Parse("a")
      Catch e As FormatException
         inputNum = 0
      End Try

      ' Stop the timer, and save the
      ' elapsed ticks for the operation.
      timePerParse.Stop()
      ticksThisTime = timePerParse.ElapsedTicks
   Case 3
      ' Parse an invalid value using
      ' the TryParse statement.
      ' Start a new stopwatch timer.
      timePerParse = Stopwatch.StartNew()

      If Not Int32.TryParse("a", inputNum) Then
         inputNum = 0
      End If

      ' Stop the timer, and save the
      ' elapsed ticks for the operation.
      timePerParse.Stop()
      ticksThisTime = timePerParse.ElapsedTicks

   Case Else
End Select

Açıklamalar

Bu özellik, temel zamanlayıcı mekanizmasında geçen değer işaretlerinin sayısını temsil eder. Değer işareti, zamanlayıcının ölçebileceği en küçük zaman Stopwatch birimidir. Frequency Değeri saniye sayısına dönüştürmek ElapsedTicks için alanını kullanın.

Örnek çalışırken veya durdurulurken Elapsed , ElapsedMillisecondsve ElapsedTicks özelliklerini Stopwatchsorgulayabilirsiniz. Stopwatch çalışırken geçen zaman özellikleri sürekli olarak artar; örnek durdurulduğunda sabit kalır.

Varsayılan olarak, bir Stopwatch örneğin geçen zaman değeri tüm ölçülen zaman aralıklarının toplamına eşittir. Start çağrılarının her biri, geçen kümülatif sürede saymaya başlar; her Stop çağrısı geçerli aralık ölçümlerini sona erdirir ve kümülatif geçen zaman değerini dondurar. Mevcut bir Reset örneğinde geçen kümülatif süreyi temizlemek için Stopwatch yöntemini kullanın.

Note

Stopwatch keneler ile DateTime.Ticksfarklıdır. Değerdeki DateTime.Ticks her değer değeri bir 100 nanosaniyelik aralığı temsil eder. Değerdeki ElapsedTicks her değer değeri, değerine bölünen Frequency1 saniyeye eşit zaman aralığını temsil eder.

Şunlara uygulanır

Ayrıca bkz.