projects/wms-framework/src/lib/helpers/DispatcherTimer.ts
Class to execute operations on a regular time interval
Properties |
|
Methods |
Accessors |
Private enabled |
Default value : false
|
Public Interval |
Type : TimeRange
|
Default value : TimeRange.FromMilliseconds(1000)
|
Time interval |
Private intervalToCancel |
Default value : -1
|
Public Tick |
Type : SubscriptionEvent<void>
|
Default value : new SubscriptionEvent()
|
Event that is executed in the specificed time interval |
Public Start |
Start()
|
Starts the interval object
Returns :
void
|
Public Stop |
Stop()
|
Stops the interval
Returns :
void
|
IsEnabled | ||||||
getIsEnabled()
|
||||||
Verifies if the the timer is enable |
||||||
setIsEnabled(value: boolean)
|
||||||
Parameters :
Returns :
void
|
import { TimeRange } from '../baseframework';
import { SubscriptionEvent } from '../utils/SubscriptionEvent';
/**
* Class to execute operations on a regular time interval
*
* @export
* @class DispatcherTimer
* @wType System.Windows.Threading.DispatcherTimer
*/
export class DispatcherTimer {
/**
* Time interval
*
* @type {TimeRange}
* @memberof DispatcherTimer
*/
public Interval: TimeRange = TimeRange.FromMilliseconds(1000);
/**
* Event that is executed in the specificed time interval
*
* @memberof DispatcherTimer
*/
public Tick: SubscriptionEvent<(e: any, a: any) => void> =
new SubscriptionEvent();
private intervalToCancel = -1;
private enabled = false;
/**
* Verifies if the the timer is enable
*
* @memberof DispatcherTimer
*/
public get IsEnabled() {
return this.enabled;
}
public set IsEnabled(value: boolean) {
this.enabled = value;
}
/**
* Starts the interval object
*
* @memberof DispatcherTimer
*/
public Start() {
this.enabled = true;
if (this.intervalToCancel === -1) {
this.intervalToCancel = window.setInterval(() => {
this.Tick.fire([this, null]);
}, this.Interval.TotalMilliseconds);
}
}
/**
* Stops the interval
*
* @memberof DispatcherTimer
*/
public Stop(): void {
this.enabled = false;
window.clearInterval(this.intervalToCancel);
this.intervalToCancel = -1;
}
}