Jaa


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 ref class ThreadPoolTimer sealed
/// [Windows.Foundation.Metadata.ContractVersion(Windows.Foundation.UniversalApiContract, 65536)]
/// [Windows.Foundation.Metadata.MarshalingBehavior(Windows.Foundation.Metadata.MarshalingType.Agile)]
/// [Windows.Foundation.Metadata.Threading(Windows.Foundation.Metadata.ThreadingModel.Both)]
class ThreadPoolTimer final
[Windows.Foundation.Metadata.ContractVersion(typeof(Windows.Foundation.UniversalApiContract), 65536)]
[Windows.Foundation.Metadata.MarshalingBehavior(Windows.Foundation.Metadata.MarshalingType.Agile)]
[Windows.Foundation.Metadata.Threading(Windows.Foundation.Metadata.ThreadingModel.Both)]
public sealed class ThreadPoolTimer
Public NotInheritable Class ThreadPoolTimer
Inheritance
Object Platform::Object IInspectable ThreadPoolTimer
Attributes

Windows requirements

Device family
Windows 10 (introduced in 10.0.10240.0)
API contract
Windows.Foundation.UniversalApiContract (introduced in v1.0)

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

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

Period

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

Methods

Cancel()

Cancels a timer.

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.

CreatePeriodicTimer(TimerElapsedHandler, TimeSpan)

Creates a periodic timer.

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.

CreateTimer(TimerElapsedHandler, TimeSpan)

Creates a single-use timer.

Applies to