2025-10-11 18:25:59 +08:00

95 lines
2.5 KiB
C#
Raw Permalink Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

/*
* <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());
}
}
}
}