95 lines
2.5 KiB
C#
Raw Normal View History

2025-10-11 18:25:59 +08:00
/*
* <copyright>
Company="公司"
2020-2025
Author=JCH
Path=XiaoZhiSharp.Kernels.PushTimer.cs
* <copyright>
* --------------------------------------------------------------
* 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
{
/// <summary>
/// 消息推送定时器
/// </summary>
public class PushTimer
{
private bool _IsPushTimer = false;
private System.Timers.Timer _Timer = null;
public event EventHandler OnPushTimer;
/// <summary>
/// 是否启动设备时钟如果为真则调用定时执行OnPushTimer函数
/// </summary>
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;
}
}
/// <summary>
/// 时钟的定时周期决定多长时间调用一次OnPushTimer函数
/// </summary>
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;
}
/// <summary>
/// 时钟定时调用的函数,可以重写此函数接口
/// </summary>
private void CallPushTimer()
{
if (OnPushTimer != null)
{
OnPushTimer(this, new EventArgs());
}
}
}
}