DispatcherTimer クラス

定義

指定した時間の間隔で、指定した優先順位で処理される Dispatcher キューに統合されているタイマー。

public ref class DispatcherTimer
public class DispatcherTimer
type DispatcherTimer = class
Public Class DispatcherTimer
継承
DispatcherTimer

次の例では、a の内容をDispatcherTimer更新し、メソッドを呼び出すメソッドをInvalidateRequerySuggested作成しますCommandManagerLabel

という名前dispatcherTimerDispatcherTimerオブジェクトが作成されます。 イベント ハンドラーdispatcherTimer_TickがイベントにTickdispatcherTimer追加されます。 オブジェクト Interval を使用して 1 秒に TimeSpan 設定され、タイマーが開始されます。

//  DispatcherTimer setup
dispatcherTimer = new System.Windows.Threading.DispatcherTimer();
dispatcherTimer.Tick += new EventHandler(dispatcherTimer_Tick);
dispatcherTimer.Interval = new TimeSpan(0,0,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、現在の秒を表示する a を更新LabelInvalidateRequerySuggestedCommandManager、.

//  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 ループの先頭で再評価されます。

タイマーは、時間間隔が発生したときに正確に実行されるとは限りませんが、時間間隔が発生する前に実行されないことが保証されます。 これは、他の操作と同様に、操作がDispatcherキューに配置されるためDispatcherTimerです。 操作の DispatcherTimer 実行時は、キュー内の他のジョブとその優先順位に依存します。

WPF アプリケーションで a System.Timers.Timer を使用する場合は、ユーザー インターフェイス (UI) スレッドとは別のスレッドで実行することに System.Timers.Timer 注目してください。 ユーザー インターフェイス (UI) スレッド上のオブジェクトにアクセスするには、ユーザー インターフェイス (UI) スレッドInvokeBeginInvokeに操作Dispatcherをポストする必要があります。 a ではなく a を DispatcherTimer 使用する System.Timers.Timer 理由は、 DispatcherTimer 同じスレッド Dispatcher で実行され、a DispatcherPriority DispatcherTimerを .

オブジェクトのメソッドがタイマーにバインドされるたびに、A 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)

events

Tick

タイマー間隔が経過すると発生します。

適用対象