ThreadPoolTimer ThreadPoolTimer ThreadPoolTimer ThreadPoolTimer Class

Definition

Represents a timer created with CreateTimer or CreatePeriodicTimer.

Note

The ThreadPool API is supported for desktop as well as UWP apps.

public : sealed class ThreadPoolTimer : IThreadPoolTimer
struct winrt::Windows::System::Threading::ThreadPoolTimer : IThreadPoolTimer
public sealed class ThreadPoolTimer : IThreadPoolTimer
Public NotInheritable Class ThreadPoolTimer Implements IThreadPoolTimer
Attributes
Windows 10 requirements
Device family
Windows 10 (introduced v10.0.10240.0)
API contract
Windows.Foundation.UniversalApiContract (introduced v1)

Examples

The following code shows the creation of a periodic timer by passing in a TimerElapsedHandler delegate method.

int period = 1000;

ThreadPoolTimer PeriodicTimer =
    ThreadPoolTimer.CreatePeriodicTimer(ExampleTimerElapsedHandler,
                                        TimeSpan.FromMilliseconds(period));

When your app is done using the timer, it should be cancelled. The following code cancels the periodic timer created in the previous example.

if (PeriodicTimer != null)
{
    PeriodicTimer.Cancel();
}

Remarks

The CreatePeriodicTimer or CreateTimer method can be used to create this object.

Note

A TimeSpan value of zero (or any value less than 1 millisecond) will cause the periodic timer to behave as a single-shot timer.

Properties

Delay Delay Delay Delay

Gets the timeout value of a single-use timer created with CreateTimer.

Period Period Period Period

Gets the timeout value of a periodic timer created with CreatePeriodicTimer.

Methods

Cancel() Cancel() Cancel() Cancel()

Cancels a timer.

CreatePeriodicTimer(TimerElapsedHandler, TimeSpan) CreatePeriodicTimer(TimerElapsedHandler, TimeSpan) CreatePeriodicTimer(TimerElapsedHandler, TimeSpan) CreatePeriodicTimer(TimerElapsedHandler, TimeSpan)

Creates a periodic timer.

CreatePeriodicTimer(TimerElapsedHandler, TimeSpan, TimerDestroyedHandler) CreatePeriodicTimer(TimerElapsedHandler, TimeSpan, TimerDestroyedHandler) CreatePeriodicTimer(TimerElapsedHandler, TimeSpan, TimerDestroyedHandler) CreatePeriodicTimer(TimerElapsedHandler, TimeSpan, TimerDestroyedHandler)

Creates a periodic timer and specifies a method to call after the periodic timer is complete. The periodic timer is complete when the timer has expired without being reactivated, and the final call to handler has finished.

CreateTimer(TimerElapsedHandler, TimeSpan) CreateTimer(TimerElapsedHandler, TimeSpan) CreateTimer(TimerElapsedHandler, TimeSpan) CreateTimer(TimerElapsedHandler, TimeSpan)

Creates a single-use timer.

CreateTimer(TimerElapsedHandler, TimeSpan, TimerDestroyedHandler) CreateTimer(TimerElapsedHandler, TimeSpan, TimerDestroyedHandler) CreateTimer(TimerElapsedHandler, TimeSpan, TimerDestroyedHandler) CreateTimer(TimerElapsedHandler, TimeSpan, TimerDestroyedHandler)

Creates a single-use timer and specifies a method to call after the timer is complete. The timer is complete when the timer has expired and the final call to handler has finished.