DispatcherQueueTimer DispatcherQueueTimer DispatcherQueueTimer DispatcherQueueTimer Class

Definition

Some information relates to pre-released product which may be substantially modified before it’s commercially released. Microsoft makes no warranties, express or implied, with respect to the information provided here.

Prerelease APIs are identified by a Prerelease label.

[Contains prerelease APIs.]
Executes a task in a DispatcherQueue periodically after a time interval has elapsed.

public : sealed class DispatcherQueueTimer : IDispatcherQueueTimerpublic sealed class DispatcherQueueTimer : IDispatcherQueueTimerPublic NotInheritable Class DispatcherQueueTimer Implements IDispatcherQueueTimer// This API is not available in Javascript.
Attributes
Windows 10 requirements
Device family
Windows 10 Insider Preview (introduced v10.0.16257.0)
API contract
Windows.Foundation.UniversalApiContract (introduced v5)

Examples

public void ConfigureRepeatingTimer()
{

    _queueController = DispatcherQueueController.CreateOnDedicatedThread();

    _queue = _queueController.DispatcherQueue;



    _repeatingTimer = _queue.CreateTimer ();

    _repeatingTimer.Interval = TimeSpan.FromSeconds(5);



    // The tick handler will be invoked repeatedly after every 5

    // seconds on the dedicated thread.

    _repeatingTimer.Tick += (s, e) =>

    {

        DoWork();

    };



    // Start the Timer

    _repeatingTimer.Start();

}


private DispatcherQueue _queue;
private DispatcherQueueController _queueController;
private DispatcherQueueTimer _repeatingTimer;

Remarks

The system guarantees to invoke the event handler only after the specified duration expires. However, there may be some delay before the tick handler is invoked if there are other pending work items in the queue.

Timer tasks run at a priority lower than idle.

Timers don’t keep the DispatcherQueue event loop alive. Timers created after the DispatcherQueue event loop has stopped will not be processed.

Properties

Interval Interval Interval Interval

Prerelease. Gets and sets the interval for the timer.

public : TimeSpan Interval { get; set; }public TimeSpan Interval { get; set; }Public ReadWrite Property Interval As TimeSpan// This API is not available in Javascript.
Value
TimeSpan TimeSpan TimeSpan TimeSpan

The amount of time before the timer ticks.

Remarks

If you change the DispatcherQueueTimer.Interval while the timer is running, the timer will restart with the new value.

IsRepeating IsRepeating IsRepeating IsRepeating

Prerelease. Indicates whether the timer is repeating.

public : PlatForm::Boolean IsRepeating { get; set; }public bool IsRepeating { get; set; }Public ReadWrite Property IsRepeating As bool// This API is not available in Javascript.
Value
PlatForm::Boolean bool bool bool

True indicates that the timer fires every DispatcherQueueTimer.Interval; false means that it fires once, after DispatcherQueueTimer.Interval elapses.

Remarks

If you change the IsRepeating value while the timer is running, the timer will restart with the new value.

IsRunning IsRunning IsRunning IsRunning

Prerelease. Indicates whether the timer is currently running.

public : PlatForm::Boolean IsRunning { get; }public bool IsRunning { get; }Public ReadOnly Property IsRunning As bool// This API is not available in Javascript.
Value
PlatForm::Boolean bool bool bool

True indicates that the timer is running; otherwise false

Methods

Start() Start() Start() Start()

Prerelease. Starts the timer.

public : void Start()public void Start()Public Function Start() As void// This API is not available in Javascript.

Stop() Stop() Stop() Stop()

Prerelease. Stops the timer.

public : void Stop()public void Stop()Public Function Stop() As void// This API is not available in Javascript.

Events

Tick Tick Tick Tick

Prerelease. Event that fires when the timer Interval elapses.

public : event TypedEventHandler Tick<DispatcherQueueTimer,  object>public event TypedEventHandler Tick<DispatcherQueueTimer,  object>Public Event Tick<DispatcherQueueTimer,  object>// This API is not available in Javascript.