DispatcherTimer 클래스

정의

지정된 시간 간격과 우선 순위로 처리되는 Dispatcher 큐로 통합되는 타이머입니다.

public ref class DispatcherTimer
public class DispatcherTimer
type DispatcherTimer = class
Public Class DispatcherTimer
상속
DispatcherTimer

예제

다음 예제에서는 DispatcherTimer 의 콘텐츠를 업데이트 하는 Label 호출을 InvalidateRequerySuggested 메서드를는 CommandManager합니다.

A DispatcherTimer 개체인 dispatcherTimer 만들어집니다. 이벤트 처리기 dispatcherTimer_Tick 에 추가 되는 Tick 이벤트를 dispatcherTimer입니다. 합니다 Interval 을 사용 하 여 1 초로 설정 됩니다는 TimeSpan 개체 및 타이머를 시작 합니다.

//  DispatcherTimer setup
dispatcherTimer = new System.Windows.Threading.DispatcherTimer();
dispatcherTimer.Tick += new EventHandler(dispatcherTimer_Tick);
dispatcherTimer.Interval = TimeSpan.FromSeconds(1);
dispatcherTimer.Start();
'  DispatcherTimer setup
dispatcherTimer = New Threading.DispatcherTimer()
AddHandler dispatcherTimer.Tick, AddressOf dispatcherTimer_Tick
dispatcherTimer.Interval = New TimeSpan(0,0,1)
dispatcherTimer.Start()

Tick 이벤트 처리기 업데이트를 Label 현재를 두 번째로, 표시 하 고 호출한 InvalidateRequerySuggestedCommandManager합니다.

//  System.Windows.Threading.DispatcherTimer.Tick handler
//
//  Updates the current seconds display and calls
//  InvalidateRequerySuggested on the CommandManager to force 
//  the Command to raise the CanExecuteChanged event.
private void dispatcherTimer_Tick(object sender, EventArgs e)
{
    // Updating the Label which displays the current second
    lblSeconds.Content = DateTime.Now.Second;

    // Forcing the CommandManager to raise the RequerySuggested event
    CommandManager.InvalidateRequerySuggested();
}
'  System.Windows.Threading.DispatcherTimer.Tick handler
'
'  Updates the current seconds display and calls
'  InvalidateRequerySuggested on the CommandManager to force 
'  the Command to raise the CanExecuteChanged event.
Private Sub dispatcherTimer_Tick(ByVal sender As Object, ByVal e As EventArgs)
    ' Updating the Label which displays the current second
    lblSeconds.Content = Date.Now.Second

    ' Forcing the CommandManager to raise the RequerySuggested event
    CommandManager.InvalidateRequerySuggested()
End Sub

설명

합니다 DispatcherTimer 맨 위에 있는 식이 다시 계산 됩니다 모든 Dispatcher 루프입니다.

타이머 간격 발생 하지만가 시간 간격이 발생 하기 전에 실행 되지 않도록 보장 됩니다 될 때 정확 하 게 실행 되도록 보장 되지 않습니다. 왜냐하면 DispatcherTimer 작업에 배치 되는 Dispatcher 다른 작업 처럼 큐입니다. 경우는 DispatcherTimer 작업이 실행 되는 큐 및 해당 우선 순위에 있는 다른 작업에 따라 달라 집니다.

System.Timers.Timer 가 WPF 애플리케이션 System.Timers.Timer 에서 사용되는 경우 는 UI(사용자 인터페이스) 스레드와 다른 스레드에서 실행됩니다. UI(사용자 인터페이스) 스레드의 개체에 액세스하려면 또는 BeginInvoke를 사용하여 Invoke UI(사용자 인터페이스) 스레드의 에 작업을 Dispatcher 게시해야 합니다. 사용 하는 이유는 DispatcherTimer 와 반대로 System.Timers.Timer 있는 DispatcherTimer 동일한 스레드에서 실행 되는 DispatcherDispatcherPriority 에 설정할 수 있습니다를 DispatcherTimer.

DispatcherTimer 상태로 유지 합니다 개체 때마다 타이머 개체의 메서드는 바인딩됩니다.

생성자

DispatcherTimer()

DispatcherTimer 클래스의 새 인스턴스를 초기화합니다.

DispatcherTimer(DispatcherPriority)

지정된 우선 순위로 타이머 이벤트를 처리하는 DispatcherTimer 클래스의 새 인스턴스를 초기화합니다.

DispatcherTimer(DispatcherPriority, Dispatcher)

지정된 DispatcherTimer에서 지정된 우선 순위로 실행되는 Dispatcher 클래스의 새 인스턴스를 초기화합니다.

DispatcherTimer(TimeSpan, DispatcherPriority, EventHandler, Dispatcher)

지정된 시간 간격, 우선 순위, 이벤트 처리기 및 DispatcherTimer를 사용하는 Dispatcher 클래스의 새 인스턴스를 초기화합니다.

속성

Dispatcher

Dispatcher와 연결된 DispatcherTimer를 가져옵니다.

Interval

타이머 틱 사이의 시간 간격을 가져오거나 설정합니다.

IsEnabled

타이머가 실행 중인지 여부를 나타내는 값을 가져오거나 설정합니다.

Tag

사용자 정의 데이터를 가져오거나 설정합니다.

메서드

Equals(Object)

지정된 개체가 현재 개체와 같은지 확인합니다.

(다음에서 상속됨 Object)
GetHashCode()

기본 해시 함수로 작동합니다.

(다음에서 상속됨 Object)
GetType()

현재 인스턴스의 Type을 가져옵니다.

(다음에서 상속됨 Object)
MemberwiseClone()

현재 Object의 단순 복사본을 만듭니다.

(다음에서 상속됨 Object)
Start()

DispatcherTimer를 시작합니다.

Stop()

DispatcherTimer를 중지합니다.

ToString()

현재 개체를 나타내는 문자열을 반환합니다.

(다음에서 상속됨 Object)

이벤트

Tick

타이머 간격이 경과되면 발생합니다.

적용 대상