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

ASP
ASP页面随机添加字符实现防复制的代码
ASP中应用事务处理技巧
asp下比较全面的获取IP地址的代码
ASP实现缓存类无错版
asp下实现批量插入数据的方法
asp下用ADODB.Stream代替FSO读取文本文件
asp之基于adodb.stream的文件操作类
自己写的文件操作的function和Sub vb.net dll
kesion科讯V4.0管理员Key工具
asp 获取access系统表,查询等操作代码
asp之字符串函数示例
asp之日期和时间函数示例
ASP 关于动态数据显示页面得锚点
Asp无组件上传进度条解决方案
ASP控制每页打印行数
用ASP实现分级权限控制
ASP在服务器自动解压RAR文件
用ASP实现远程将文件批量改名的代码
在Asp程序中取得表单所有内容的代码
使用ASP实现网站的“目录树”管理的代码

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


出处:互联网   整理: 软晨网(RuanChen.com)   发布: 2009-11-03   浏览: 129 ::
收藏到网摘: 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;
}