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

ASP
asp调用存储过程
利用批处理文件和 vbs 脚本实现网站视频自动录制
ASP、vbscript编码模板
FileSystem对象常用的文件操作函数有哪些?
asp显示日历效果
sql语句的一些集合
ASP语法注释
函数名称 函数功能
万能数据库连接程序
记录集内随机取记录的代码
分页代码
如何在数据库中用好Transaction?
用Command对象和RecordSet对象向数据库增加记录哪一个更好
为什么在存储过程中用OLEDB方式不能返回记录集
如何查询日期类型的数据?
ASP如何获取真实IP地址
两种小偷程序的比较
使用xmlHttp结合ASP实现网页的异步调用
用ASP开"多线程"
整理了一个editplus的剪辑文件(ASP方面的内容)

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


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