Stopwatch.ElapsedTicks Stopwatch.ElapsedTicks Stopwatch.ElapsedTicks Stopwatch.ElapsedTicks Property

Definition

Ruft die gesamte verstrichene Zeit, die von der aktuellen Instanz gemessen wurde, in Zeitgeberintervallen (Ticks) ab. Gets the total elapsed time measured by the current instance, in timer ticks.

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

Property Value

Eine schreibgeschützte Long-Integer-Zahl, die die Gesamtanzahl der von der aktuellen Instanz gemessenen Zeitgeberintervalle angibt. A read-only long integer representing the total number of timer ticks measured by the current instance.

Examples

Im folgenden Beispiel wird die Stopwatch Klasse zum Messen der Leistung von vier verschiedenen Implementierungen für die Analyse einer ganze Zahl aus einer Zeichenfolge.The following example uses the Stopwatch class to measure the performance of four different implementations for parsing an integer from a string. Dieses Codebeispiel ist Teil eines umfangreicheren Beispiels für die Stopwatch Klasse.This code example is part of a larger example provided for the Stopwatch class.

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

Remarks

Diese Eigenschaft stellt die Anzahl der verstrichenen Ticks im zugrunde liegenden Zeitgebermechanismus.This property represents the number of elapsed ticks in the underlying timer mechanism. Ein Tick ist die kleinste Einheit der Zeit, die die Stopwatch Timer messen kann.A tick is the smallest unit of time that the Stopwatch timer can measure. Verwenden der Frequency Feld konvertieren die ElapsedTicks Wert in eine Anzahl von Sekunden.Use the Frequency field to convert the ElapsedTicks value into a number of seconds.

Sie können die Eigenschaften Abfragen Elapsed, ElapsedMilliseconds, und ElapsedTicks während der Stopwatch Instanz ist, ausgeführt oder beendet.You can query the properties Elapsed, ElapsedMilliseconds, and ElapsedTicks while the Stopwatch instance is running or stopped. Zwar der verstrichenen Zeit, die Eigenschaften stetigen Anstieg der Stopwatch wird ausgeführt; sie konstant bleiben, wenn die Instanz beendet wird.The elapsed time properties steadily increase while the Stopwatch is running; they remain constant when the instance is stopped.

Standardmäßig wird die verstrichene Zeit-Wert, der eine Stopwatch Instanz gleich die Summe alle Intervalle der gemessene Zeit.By default, the elapsed time value of a Stopwatch instance equals the total of all measured time intervals. Jeder Aufruf von Start beginnt die Zählung mit die kumulative Zeitspanne; jeder Aufruf von Stop endet die Messung des aktuellen Intervalls und friert die kumulierte verstrichene Zeit-Wert.Each call to Start begins counting at the cumulative elapsed time; each call to Stop ends the current interval measurement and freezes the cumulative elapsed time value. Verwenden der Reset Methode zum Löschen der kumulierte verstrichene Zeit in einer vorhandenen Stopwatch Instanz.Use the Reset method to clear the cumulative elapsed time in an existing Stopwatch instance.

Hinweis

Stopwatch Ticks unterscheiden sich von DateTime.Ticks.Stopwatch ticks are different from DateTime.Ticks. Jeder Takt in die DateTime.Ticks Wert darstellt, ein 100-Nanosekunden-Intervall.Each tick in the DateTime.Ticks value represents one 100-nanosecond interval. Jeder Takt in die ElapsedTicks Wert darstellt, das Zeitintervall, die gleich 1 Sekunde, dividiert durch die Frequency.Each tick in the ElapsedTicks value represents the time interval equal to 1 second divided by the Frequency.

Applies to

See Also