Windows.System.Threading.ThreadPoolTimer

August 14, 2018 ยท View on GitHub

-description

Represents a timer created with CreateTimer or CreatePeriodicTimer.

Note

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

-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.

-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();
}

-see-also