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 süreölçer değer sayısını temsil eden salt okunur uzun bir tamsayı.

Örnekler

Aşağıdaki örnek, bir tamsayıyı Stopwatch dizeden 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.

Int64 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", 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", inputNum ) )
      {
         inputNum = 0;
      }
      
      // Stop the timer, and save the
      // elapsed ticks for the operation.
      timePerParse->Stop();
      ticksThisTime = timePerParse->ElapsedTicks;
      break;

   default:
      break;
}
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 kene sayısını temsil eder. Değer çizgisi, 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 Stopwatch , ElapsedMillisecondsve ElapsedTicks özelliklerini Elapsedsorgulayabilirsiniz. Geçen zaman özellikleri çalışırken sürekli olarak artar Stopwatch ; ö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. çağrısının Start her biri kümülatif geçen sürede saymaya başlar; her çağrısı Stop geçerli aralık ölçümlerini sona erdirir ve kümülatif geçen zaman değerini dondurar. Reset Mevcut Stopwatch örnekteki birikmeli geçen süreyi temizlemek için yöntemini kullanın.

Not

Stopwatch keneler ile DateTime.Ticksfarklıdır. Değerdeki DateTime.Ticks her değer değeri 100 nanosaniyelik bir 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.