Pip-Services-Commons-Dotnet
Public Member Functions | Properties | Private Attributes | List of all members
PipServices3.Commons.Run.FixedRateTimer Class Reference

Timer that is triggered in equal time intervals. More...

Public Member Functions

 FixedRateTimer ()
 Creates new instance of the timer with default parameters. More...
 
 FixedRateTimer (Action task, int interval, int delay)
 Creates new instance of the timer and sets its values. More...
 
void Start ()
 Starts the timer. More...
 
void Restart ()
 Restart the timer. More...
 
void Stop ()
 Stops the timer. More...
 

Properties

Action Task [get, set]
 
int Delay [get, set]
 
int Interval [get, set]
 
bool IsStarted [get, private set]
 

Private Attributes

Timer _timer
 
readonly object _lock = new object()
 

Detailed Description

Timer that is triggered in equal time intervals.

It has summetric cross-language implementation and is often used by Pip.Services toolkit to perform periodic processing and cleanup in microservices.

class MyComponent
{
var timer = new FixedRateTimer(() => { this.cleanup }, 60000, 0);
...
public void )pen(string correlationId)
{
...
timer.Start();
...
}
public void Open(string correlationId)
{
...
timer.Stop();
...
}
private void Cleanup()
{
...
}
...
}

See INotifiable

Constructor & Destructor Documentation

◆ FixedRateTimer() [1/2]

PipServices3.Commons.Run.FixedRateTimer.FixedRateTimer ( )

Creates new instance of the timer with default parameters.

◆ FixedRateTimer() [2/2]

PipServices3.Commons.Run.FixedRateTimer.FixedRateTimer ( Action  task,
int  interval,
int  delay 
)

Creates new instance of the timer and sets its values.

Parameters
task(optional) a Notifiable object to call when timer is triggered.
interval(optional) an interval to trigger timer in milliseconds.
delay(optional) a delay before the first triggering in milliseconds.

Member Function Documentation

◆ Restart()

void PipServices3.Commons.Run.FixedRateTimer.Restart ( )

Restart the timer.

◆ Start()

void PipServices3.Commons.Run.FixedRateTimer.Start ( )

Starts the timer.

Initially the timer is triggered after delay.After that it is triggered after interval until it is stopped.

◆ Stop()

void PipServices3.Commons.Run.FixedRateTimer.Stop ( )

Stops the timer.


The documentation for this class was generated from the following file: