## wxTimer

The wxTimer class allows you to execute code at specified intervals. Its precision is platform-dependent, but in general will not be better than 1ms nor worse than 1s.

There are two different ways to use this class:

1. You may derive a new class from wxTimer and override the Notify member to perform the required action.
2. Or you may redirect the notifications to any wxEvtHandler derived object by using the non default constructor or SetOwner. Then use `EVT_TIMER` macro to connect it to the event handler which will receive wxTimerEvent notifications.

In any case, you must start the timer with Start after constructing it before it actually starts sending notifications. It can be stopped later with Stop.

Derived from

wxObject

Include files

<wx/timer.h>

See also

::wxStartTimer, ::wxGetElapsedTime, wxStopWatch

Members

wxTimer::wxTimer
wxTimer::~wxTimer
wxTimer::GetInterval
wxTimer::IsOneShot
wxTimer::IsRunning
wxTimer::Notify
wxTimer::SetOwner
wxTimer::Start
wxTimer::Stop

### wxTimer::wxTimer

wxTimer()

Default constructor. If you use it to construct the object and don't call SetOwner later, you must override Notify method to process the notifications.

wxTimer(wxEvtHandler *owner, int id = -1)

Creates a timer and associates it with owner. Please see SetOwner for the description of parameters.

### wxTimer::~wxTimer

~wxTimer()

Destructor. Stops the timer if it is running.

### wxTimer::GetInterval

wxtimergetinterval

int GetInterval() const

Returns the current interval for the timer (in milliseconds).

### wxTimer::IsOneShot

bool IsOneShot() const

Returns TRUE if the timer is one shot, i.e. if it will stop after firing the first notification automatically.

### wxTimer::IsRunning

bool IsRunning() const

Returns TRUE if the timer is running, FALSE if it is stopped.

### wxTimer::Notify

void Notify()

This member should be overridden by the user if the default constructor was used and SetOwner wasn't called.

Perform whatever action which is to be taken periodically here.

### wxTimer::SetOwner

void SetOwner(wxEvtHandler *owner, int id = -1)

Associates the timer with the given owner object. When the timer is running, the owner will receive timer events with id equal to id specified here.

### wxTimer::Start

bool Start(int milliseconds = -1, bool oneShot=FALSE)

(Re)starts the timer. If milliseconds parameter is -1 (value by default), the previous value is used. Returns FALSE if the timer could not be started, TRUE otherwise (in MS Windows timers are a limited resource).

If oneShot is FALSE (the default), the Notify function will be called repeatedly until the timer is stopped. If TRUE, it will be called only once and the timer will stop automatically.

### wxTimer::Stop

void Stop()

Stops the timer.