当前位置: 首页 > 图文教程 > 网络编程 > ASP > 在B/S系统中引入定时器的功能

ASP
asp #include命令
推荐下天枫常用ASP函数封装,推荐大家使用
asp最简单最实用的计数器
用asp实现的iframe批量替换工具
ASPWebPack 代码 提供下载
asp分页生成html的程序脚本代码
比较不错的asp单表单字段多条件查询
asp下用replace非正则实现代码运行功能的代码
UpdatePanel触发javascript脚本的方法附代码
生成EAN13标准的条形码的ASP代码实例
asp空间奸商查询系统
ASPWebPack(整站文件备份系统) v1.0.2 黑客也用
ASP+FSO可视化目录编历(可增、删、改)下载
提高ASP效率的五大技巧
ASP生成随机字符串(数字+大小写字母)的代码
ASP下存储过程编写入门全接触
利用 cache 做对比静态页的网页技术
ASP生成静态文件编码为UTF-8格式的HTML文件
ASP下的两个防止SQL注入式攻击的Function
asp下的风讯用的SQL通用防注入模块提供了

ASP 中的 在B/S系统中引入定时器的功能


出处:互联网   整理: 软晨网(RuanChen.com)   发布: 2009-11-03   浏览: 135 ::
收藏到网摘: n/a

过去的一些使用ASP技术开发的B/S系统中,需要系统定时执行一些方法时一直都
找不到好的解决方案(如果有,那一定是我浅薄了,我们讨论讨论)。
现在在ASP。NET中可以使用自定义实现IHttpModule接口的类来加载一个定时器。
public class OilIHttpModule : IHttpModule 
{
 public static Timer analyseTimer;//分析数据的定时器
 static int intLastTrialInfo_id;//最后分析的ID
 static long intAnalyseInterval= 10000;//间隔的时间
 public OilIHttpModule()
 { }
 public String ModuleName
 {
  get { return "OilModule"; }
 }
 ///初始化模型
 public void Init(HttpApplication application)
 {
  application.BeginRequest += (new EventHandler
(this.Application_BeginRequest));
//增加处理请求时触发的事件
  if(intLastTrialInfo_id==0)
  { //获取最后分析的
   trialInfo_id intLastTrialInfo_id =
globalMethod.getLastAnalyseTrialInfo_id();
  }
  //判断Timer是否存在,如果没有则实例化
  if(analyseTimer==null)
   analyseTimer = new Timer(new TimerCallback(analyseData),null,
intAnalyseInterval,intAnalyseInterval);
 }
 private void Application_BeginRequest(Object source, EventArgs e) 
 {
  //null
  // HttpApplication application = (HttpApplication)source;
  // application.Response.Write(intLastTrialInfo_id.ToString());
 }
 ///要定时执行的程序片段
 private void analyseData(object obj)
 {
  ///很重要,可以防止定时器被重新生成
  analyseTimer.Change( System.Threading.Timeout.Infinite,
intAnalyseInterval );
  // StatsInterval
  int intTrialInfo_idAfterUpdate;
  intTrialInfo_idAfterUpdate =
globalMethod.AnalyseTrialFromTrialInfo_id(intLastTrialInfo_id);
  if(intTrialInfo_idAfterUpdate > intLastTrialInfo_id)
  {
   intLastTrialInfo_id = intTrialInfo_idAfterUpdate;
  }
 }
 public void Dispose()
 {
  analyseTimer = null;
}