Stopwatch.Stop 메서드

정의

간격에 대한 경과 시간 측정을 중지합니다.

public:
 void Stop();
public void Stop ();
member this.Stop : unit -> unit
Public Sub Stop ()

예제

다음 예제에서는 사용 하는 방법에 설명 합니다 Stop 애플리케이션의 실행 시간을 측정 하는 타이머를 중지 하는 방법입니다.

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

설명

일반적인 Stopwatch 시나리오에서는 메서드를 Start 호출한 다음 결국 메서드를 Stop 호출한 다음 속성을 사용하여 Elapsed 경과된 시간을 검사.

메서드는 Stop 현재 시간 간격 측정을 종료합니다. 실행되지 않는 를 Stopwatch 중지해도 타이머 상태가 변경되지 않거나 경과된 시간 속성이 다시 설정되지 않습니다.

Stopwatch instance 둘 이상의 간격 Stop 을 측정하는 경우 메서드는 경과된 시간 측정을 일시 중지하는 것과 같습니다. 에 대한 Start 후속 호출은 현재 경과된 시간 값에서 측정 시간을 다시 시작합니다. Reset instance 누적 경과 시간을 지우려면 메서드를 Stopwatch 사용합니다.

적용 대상

추가 정보