说明:
// 自动生成Htm时间间隔 单位:hour (请自行替换int值数据)
CmsConstants.AUTO_MAKE_HTML_INTERVAL
// 自动生成首页、频道页htm开关 (请自行替换为Boolean值,设为true或删除相关语句计时器才有效)
CmsConstants.AUTO_MAKE_HTML_ENABLED
代码:
using System.Timers;
using Rouse.Cms.Common.Util;
namespace Rouse.Cms.Core.MyTimer
{
/// <summary>
/// MakeHtmlTimer
/// 定时生成HTML
/// </summary>
public class MakeHtmlTimer
{
/// <summary>
/// 生成Html定时器
/// </summary>
private static Timer htmlTimer = new Timer(CmsConstants.AUTO_MAKE_HTML_INTERVAL*1000*3600);
/// <summary>
/// 单例
/// </summary>
private static MakeHtmlTimer CURR_CLASS_INSTANCE = new MakeHtmlTimer();
/// <summary>
/// 构造函数
/// </summary>
private MakeHtmlTimer()
{
if (CmsConstants.AUTO_MAKE_HTML_ENABLED)
{
htmlTimer.AutoReset = true;
htmlTimer.Enabled = true;
htmlTimer.Elapsed += new System.Timers.ElapsedEventHandler(Timer_Elapsed);
}
}
/// <summary>
/// 得到单例
/// </summary>
/// <returns></returns>
public static MakeHtmlTimer getInstance()
{
return CURR_CLASS_INSTANCE;
}
/// <summary>
/// 计时器开启状态
/// </summary>
/// <returns></returns>
public Boolean isEnabled()
{
return htmlTimer.Enabled;
}
/// <summary>
/// 开始计时器
/// </summary>
public void start()
{
if (CmsConstants.AUTO_MAKE_HTML_ENABLED)
htmlTimer.Start();
}
/// <summary>
/// 停止计时器
/// </summary>
public void stop()
{
htmlTimer.Stop();
}
/// <summary>
/// 定时执行方法
/// </summary>
/// <param name="sender"></param>
/// <param name="e"></param>
private void Timer_Elapsed(object sender, System.Timers.ElapsedEventArgs e)
{
///
/// 生成首页静态页面(在此写定时器处理逻辑)
///
}
}
}
如果给你带来帮助,欢迎微信或支付宝扫一扫,赞一下。