Stopwatch.Start 메서드

정의

간격에 대한 경과 시간 측정을 시작하거나 다시 시작합니다.

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

예제

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

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 경과된 시간을 검사.

시작되면 타이머는 Stopwatch instance 중지되거나 다시 설정될 때까지 경과된 타이머 틱으로 현재 간격을 측정합니다. 이미 실행 중인 를 Stopwatch 시작해도 타이머 상태가 변경되지 않거나 경과된 시간 속성이 다시 설정되지 않습니다.

Stopwatch instance 둘 이상의 간격을 측정하면 메서드는 Start 현재 경과된 시간 값에서 측정 시간을 다시 시작합니다. Stopwatch instance instance 다시 설정될 때까지 여러 시간 간격에 걸쳐 누적 경과 시간을 계산하고 유지합니다. 를 호출 Start 하기 전에 메서드를 Reset 사용하여 instance 누적 경과 시간을 지웁 수 있습니다 Stopwatch . 메서드 ResetStartStopwatchRestart 및 를 단일 명령으로 사용합니다.

적용 대상

추가 정보