ThreadPoolTimer class
Represents a timer created with CreateTimer or CreatePeriodicTimer.
Note The ThreadPool API is supported for desktop as well as Windows Store apps.
Syntax
Attributes
- MarshalingBehaviorAttribute(Agile)
- StaticAttribute(Windows.System.Threading.IThreadPoolTimerStatics, NTDDI_WIN8)
- ThreadingAttribute(Both)
- VersionAttribute(NTDDI_WIN8)
- WebHostHiddenAttribute()
Members
The ThreadPoolTimer class has these types of members:
Methods
The ThreadPoolTimer class has these methods. It also inherits methods from the Object class.
| Method | Description |
|---|---|
| Cancel | Cancels a timer. |
| CreatePeriodicTimer(TimerElapsedHandler, TimeSpan) | Creates a periodic 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. |
| CreateTimer(TimerElapsedHandler, TimeSpan) | Creates a single-use 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. |
Properties
The ThreadPoolTimer class has these properties.
| Property | Access type | Description |
|---|---|---|
| Read-only | Gets the timeout value of a single-use timer created with CreateTimer. | |
| Read-only | Gets the timeout value of a periodic timer created with CreatePeriodicTimer. |
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. The delegate method should periodically check the Canceled property of the operation parameter, and exit gracefully if the work item has been cancelled.
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();
}
Requirements
|
Minimum supported client | Windows 8 [Windows Store apps only] |
|---|---|
|
Minimum supported server | Windows Server 2012 [Windows Store apps only] |
|
Minimum supported phone | Windows Phone 8 |
|
Namespace |
|
|
Metadata |
|
Build date: 2/25/2013
