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.

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.

Public Constructors

NameDescription
timer::timer ConstructorOverloaded. Constructs a timer messaging block that will fire a given message after a specified interval.
timer::~timer DestructorDestroys a timer messaging block.

Public Methods

NameDescription
timer::pause MethodStops 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.
timer::start MethodStarts the timer messaging block. The specified number of milliseconds after this is called, the specified value will be propagated downstream as a message.
timer::stop MethodStops the timer messaging block.

Protected Methods

NameDescription
timer::accept_message MethodAccepts a message that was offered by this timer messaging block, transferring ownership to the caller.
timer::consume_message MethodConsumes a message previously offered by the timer and reserved by the target, transferring ownership to the caller.
timer::link_target_notification MethodA callback that notifies that a new target has been linked to this timer messaging block.
timer::propagate_to_any_targets MethodTries to offer the message produced by the timer block to all of the linked targets.
timer::release_message MethodReleases a previous message reservation. (Overrides source_block::release_message.)
timer::reserve_message MethodReserves a message previously offered by this timer messaging block. (Overrides source_block::reserve_message.)
timer::resume_propagation MethodResumes propagation after a reservation has been released. (Overrides source_block::resume_propagation.)

For more information, see Asynchronous Message Blocks.

ISource

source_block

timer

Header: agents.h

Namespace: concurrency

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.

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.

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

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> *);

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.

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.

Resumes propagation after a reservation has been released.

virtual void resume_propagation();

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

Stops the timer messaging block.

void stop();

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.

Destroys a timer messaging block.

~timer();

concurrency Namespace

Show: