Edit

Share via


timer Class

A timer messaging block is a single-target source_block capable of sending a message to its target after a specified time period has elapsed or at specific intervals.

Syntax

template<class T>
class timer : public Concurrency::details::_Timer, public source_block<single_link_registry<ITarget<T>>>;

Parameters

T
The payload type of the output messages of this block.

Members

Public Constructors

Name Description
timer Overloaded. Constructs a timer messaging block that will fire a given message after a specified interval.
~timer Destructor Destroys a timer messaging block.

Public Methods

Name Description
pause Stops the timer messaging block. If it is a repeating timer messaging block, it can be restarted with a subsequent start() call. For non-repeating timers, this has the same effect as a stop call.
start Starts the timer messaging block. The specified number of milliseconds after this is called, the specified value will be propagated downstream as a message.
stop Stops the timer messaging block.

Protected Methods

Name Description
accept_message Accepts a message that was offered by this timer messaging block, transferring ownership to the caller.
consume_message Consumes a message previously offered by the timer and reserved by the target, transferring ownership to the caller.
link_target_notification A callback that notifies that a new target has been linked to this timer messaging block.
propagate_to_any_targets Tries to offer the message produced by the timer block to all of the linked targets.
release_message Releases a previous message reservation. (Overrides source_block::release_message.)
reserve_message Reserves a message previously offered by this timer messaging block. (Overrides source_block::reserve_message.)
resume_propagation Resumes propagation after a reservation has been released. (Overrides source_block::resume_propagation.)

Remarks

For more information, see Asynchronous Message Blocks.

Inheritance Hierarchy

ISource

source_block

timer

Requirements

Header: agents.h

Namespace: concurrency

accept_message

Accepts a message that was offered by this timer messaging block, transferring ownership to the caller.

virtual message<T>* accept_message(runtime_object_identity _MsgId);

Parameters

_MsgId
The runtime_object_identity of the offered message object.

Return Value

A pointer to the message object that the caller now has ownership of.

consume_message

Consumes a message previously offered by the timer and reserved by the target, transferring ownership to the caller.

virtual message<T>* consume_message(runtime_object_identity _MsgId);

Parameters

_MsgId
The runtime_object_identity of the message object being consumed.

Return Value

A pointer to the message object that the caller now has ownership of.

Remarks

Similar to accept, but is always preceded by a call to reserve.

A callback that notifies that a new target has been linked to this timer messaging block.

virtual void link_target_notification(_Inout_ ITarget<T>* _PTarget);

Parameters

_PTarget
A pointer to the newly linked target.

pause

Stops the timer messaging block. If it is a repeating timer messaging block, it can be restarted with a subsequent start() call. For non-repeating timers, this has the same effect as a stop call.

void pause();

propagate_to_any_targets

Tries to offer the message produced by the timer block to all of the linked targets.

virtual void propagate_to_any_targets(_Inout_opt_ message<T> *);

release_message

Releases a previous message reservation.

virtual void release_message(runtime_object_identity _MsgId);

Parameters

_MsgId
The runtime_object_identity of the message object being released.

reserve_message

Reserves a message previously offered by this timer messaging block.

virtual bool reserve_message(runtime_object_identity _MsgId);

Parameters

_MsgId
The runtime_object_identity of the message object being reserved.

Return Value

true if the message was successfully reserved, false otherwise.

Remarks

After reserve is called, if it returns true, either consume or release must be called to either take or release ownership of the message.

resume_propagation

Resumes propagation after a reservation has been released.

virtual void resume_propagation();

start

Starts the timer messaging block. The specified number of milliseconds after this is called, the specified value will be propagated downstream as a message.

void start();

stop

Stops the timer messaging block.

void stop();

timer

Constructs a timer messaging block that will fire a given message after a specified interval.

timer(
    unsigned int _Ms,
    T const& value,
    ITarget<T>* _PTarget = NULL,
    bool _Repeating = false);

timer(
    Scheduler& _Scheduler,
    unsigned int _Ms,
    T const& value,
    _Inout_opt_ ITarget<T>* _PTarget = NULL,
    bool _Repeating = false);

timer(
    ScheduleGroup& _ScheduleGroup,
    unsigned int _Ms,
    T const& value,
    _Inout_opt_ ITarget<T>* _PTarget = NULL,
    bool _Repeating = false);

Parameters

_Ms
The number of milliseconds that must elapse after the call to start for the specified message to be propagated downstream.

value
The value which will be propagated downstream when the timer elapses.

_PTarget
The target to which the timer will propagate its message.

_Repeating
If true, indicates that the timer will fire periodically every _Ms milliseconds.

_Scheduler
The Scheduler object within which the propagation task for the timer messaging block is scheduled is scheduled.

_ScheduleGroup
The ScheduleGroup object within which the propagation task for the timer messaging block is scheduled. The Scheduler object used is implied by the schedule group.

Remarks

The runtime uses the default scheduler if you do not specify the _Scheduler or _ScheduleGroup parameters.

~timer

Destroys a timer messaging block.

~timer();

See also

concurrency Namespace