Stopwatch.Stop Méthode
Définition
Important
Certaines informations portent sur la préversion du produit qui est susceptible d’être en grande partie modifiée avant sa publication. Microsoft exclut toute garantie, expresse ou implicite, concernant les informations fournies ici.
Arrête la mesure du temps écoulé pendant un intervalle.
public:
void Stop();
public void Stop();
member this.Stop : unit -> unit
Public Sub Stop ()
Exemples
L’exemple suivant montre comment utiliser la Stop méthode pour arrêter un minuteur qui mesure le temps d’exécution d’une application.
using System;
using System.Diagnostics;
using System.Threading;
class Program
{
static void Main(string[] args)
{
Stopwatch stopWatch = new Stopwatch();
stopWatch.Start();
Thread.Sleep(10000);
stopWatch.Stop();
// Get the elapsed time as a TimeSpan value.
TimeSpan ts = stopWatch.Elapsed;
// Format and display the TimeSpan value.
string elapsedTime = String.Format("{0:00}:{1:00}:{2:00}.{3:00}",
ts.Hours, ts.Minutes, ts.Seconds,
ts.Milliseconds / 10);
Console.WriteLine("RunTime " + elapsedTime);
}
}
Imports System.Diagnostics
Imports System.Threading
Class Program
Shared Sub Main(ByVal args() As String)
Dim stopWatch As New Stopwatch()
stopWatch.Start()
Thread.Sleep(10000)
stopWatch.Stop()
' Get the elapsed time as a TimeSpan value.
Dim ts As TimeSpan = stopWatch.Elapsed
' Format and display the TimeSpan value.
Dim elapsedTime As String = String.Format("{0:00}:{1:00}:{2:00}.{3:00}", ts.Hours, ts.Minutes, ts.Seconds, ts.Milliseconds / 10)
Console.WriteLine( "RunTime " + elapsedTime)
End Sub
End Class
Remarques
Dans un scénario classique Stopwatch , vous appelez la Start méthode, puis appelez la Stop méthode, puis vérifiez le temps écoulé à l’aide de la Elapsed propriété.
La Stop méthode met fin à la mesure d’intervalle de temps actuel. L’arrêt d’un Stopwatch élément qui n’est pas en cours d’exécution ne modifie pas l’état du minuteur ou réinitialise les propriétés de temps écoulés.
Lorsqu’une Stopwatch instance mesure plusieurs intervalles, la Stop méthode équivaut à suspendre la mesure de temps écoulé. Appel suivant pour Start reprendre la mesure du temps écoulé à partir de la valeur de temps écoulée actuelle. Utilisez la Reset méthode pour effacer le temps cumulé écoulé dans une Stopwatch instance.