95 lines
2.5 KiB
C#
95 lines
2.5 KiB
C#
|
/*
|
|||
|
* <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());
|
|||
|
}
|
|||
|
}
|
|||
|
}
|
|||
|
|
|||
|
}
|