My.Computer.Clock.TickCount 속성

업데이트: 2007년 11월

컴퓨터의 시스템 타이머에서 밀리초 수를 가져옵니다.

' Usage
Dim value As Integer = My.Computer.Clock.TickCount
' Declaration
Public ReadOnly Property TickCount As Integer

반환 값

컴퓨터 시스템 타이머의 밀리초 수를 포함하는 Integer 형식입니다.

설명

TickCount 속성은 컴퓨터가 활성화될 때 실행되는 컴퓨터의 시스템 타이머에 대한 액세스를 제공합니다. 타이머 확인 설정은 500밀리초보다 작지 않아야 합니다.

이 속성을 사용하면 응용 프로그램의 실행 시간에 따라 해당 동작을 조정할 수 있을 뿐만 아니라 이벤트에 레이블을 지정할 수도 있습니다. 이 두 작업 모두 컴퓨터 시계와는 별도로 수행됩니다.

주의:

TickCount 속성의 값이 최대 정수 값(MaxValue)에 도달하면 최소 정수 값(MinValue)(음수)으로 이동한 다음 계속 증분합니다.

컴퓨터가 계속 실행되면 TickCount는 0에서 최대 정수 값(약 24.9일)까지 증분합니다.

TickCount 속성은 운영 체제가 실행 중일 때만 증분하고 컴퓨터가 대기 모드이거나 최대 절전 모드와 같은 특정 절전 모드에 있는 경우에는 일시 중지합니다. TickCount 속성은 컴퓨터의 시계 설정과 관련이 없습니다.

My.Computer.Clock.LocalTime 속성 또는 My.Computer.Clock.GmtTime 속성을 사용하여 이 컴퓨터의 현재 현지 날짜 및 시간을 가져옵니다.

My.Computer.Clock.TickCount 속성의 동작은 Environment.TickCount 속성의 동작과 동일합니다.

예제

다음 예제에서는 실행하는 동안 컴퓨터의 시스템 시간이 변경되어도 My.Computer.Clock.TickCount 속성을 사용하여 지정된 시간(초) 동안 루프에서 작업을 실행합니다.

Public Sub LoopTask(ByVal secondsToRun As Integer)
    Dim startTicks As Integer = My.Computer.Clock.TickCount
    Do While IsTimeUp(startTicks, secondsToRun)
        ' Code to run for at least secondsToRun seconds goes here.
    Loop
End Sub

Private Function IsTimeUp( _
    ByVal startTicks As Integer, _
    ByVal seconds As Integer _
) As Boolean
    ' This function throws an overflow exception if the
    ' tick count difference is greater than 2,147,483,647,  
    ' about 24 days for My.Computer.Clock.TickCount.

    ' Use UInteger to simplify the code for roll over.
    Dim uStart As UInteger = _
        CUInt(CLng(startTicks) - Integer.MinValue)
    Dim uCurrent As UInteger = _
        CUInt(CLng(My.Computer.Clock.TickCount) - Integer.MinValue)

    ' Calculate the tick count difference.
    Dim tickCountDifference As UInteger
    If uStart <= uCurrent Then
        tickCountDifference = uCurrent - uStart
    Else
        ' Tick count rolled over.
        tickCountDifference = UInteger.MaxValue - (uStart - uCurrent)
    End If

    ' Convert seconds to milliseconds and compare.
    Return CInt(tickCountDifference) < (seconds * 1000)
End Function

요구 사항

네임스페이스:Microsoft.VisualBasic.Devices

클래스:Clock

어셈블리: Visual Basic 런타임 라이브러리(Microsoft.VisualBasic.dll)

프로젝트 형식별 사용 가능 여부

프로젝트 형식

사용 가능 여부

Windows 응용 프로그램

클래스 라이브러리

콘솔 응용 프로그램

Windows 컨트롤 라이브러리

웹 컨트롤 라이브러리

Windows 서비스

웹 사이트

권한

사용 권한이 필요하지 않습니다.

참고 항목

참조

My.Computer.Clock 개체

Environment.TickCount

Clock.TickCount