/* * Company="公司" 2020-2025 Author=JCH Path=XiaoZhiSharp.Kernels.PushTimer.cs * * -------------------------------------------------------------- * 机器名称:JCH * 文件名:PushTimer.cs * 版本号:V1.0.0.0 * 创建人:JCH * 创建时间:2025/9/25 17:24:35 * 描述: * -------------------------------------------------------------- * 修改时间:2025/9/25 17:24:35 * 修改人:JCH * 版本号:V1.0.0.0 * 描述: * -------------------------------------------------------------- */ using System; namespace XiaoZhiSharp.Kernels { /// /// 消息推送定时器 /// public class PushTimer { private bool _IsPushTimer = false; private System.Timers.Timer _Timer = null; public event EventHandler OnPushTimer; /// /// 是否启动设备时钟,如果为真,则调用定时执行OnPushTimer函数 /// public bool IsPushTimer { set { this._IsPushTimer = value; if (this._IsPushTimer) { this._Timer.Start(); this._Timer.Enabled = true; } else { this._Timer.Stop(); this._Timer.Enabled = false; } } get { return this._IsPushTimer; } } /// /// 时钟的定时周期,决定多长时间调用一次OnPushTimer函数 /// public int PushTimerInterval { get { return (int)this._Timer.Interval; } set { this._Timer.Interval = value; } } public PushTimer() { this._Timer = new System.Timers.Timer(1000) { AutoReset = true }; this._Timer.Elapsed += new System.Timers.ElapsedEventHandler((s, e) => //时钟定时回调函数 { CallPushTimer(); }); this.IsPushTimer = false; this.PushTimerInterval = 1000; } /// /// 时钟定时调用的函数,可以重写此函数接口 /// private void CallPushTimer() { if (OnPushTimer != null) { OnPushTimer(this, new EventArgs()); } } } }