다음을 통해 공유


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 실행되지 않는 중지는 타이머 상태를 변경하거나 경과된 시간 속성을 다시 설정하지 않습니다.

인스턴스가 둘 이상의 간격 StopStopwatch 측정하는 경우 메서드는 경과된 시간 측정을 일시 중지하는 것과 같습니다. 후속 호출은 Start 현재 경과된 시간 값에서 측정 시간을 다시 시작합니다. 이 메서드를 Reset 사용하여 인스턴스의 누적 경과 시간을 지울 수 있습니다 Stopwatch .

적용 대상

추가 정보