在ASP.NET中使用计时器(Timer)
来源:互联网 发布:英语教学软件 编辑:程序博客网 时间:2024/05/21 13:57
下面首先介绍我测试使用的一个例子:
首先在 global.asax 中的 Application_OnStart 事件过程中定义计时器,代码如下:
[VB.NET] global.asax
<%@ import Namespace="System.Timers" %>
<script runat="server">
Sub Application_OnStart(sender As Object, e As EventArgs)
' 创建一个计时器,单位:毫秒
Dim aTimer As New System.Timers.Timer(10000)
' 将 Fresher 指定为计时器的 Elapsed 事件处理程序
AddHandler aTimer.Elapsed, AddressOf Fresher
' AutoReset 属性为 true 时,每隔指定时间循环一次;
' 如果为 false,则只执行一次。
aTimer.AutoReset = True
aTimer.Enabled = True
' 先给 Application("TimeStamp") 指定一个初值
Application.Lock()
Application("TimeStamp") = DateTime.Now.ToString()
Application.UnLock()
End Sub
Sub Fresher(sender As Object, e As ElapsedEventArgs)
Application.Lock()
Application("TimeStamp") = DateTime.Now.ToString()
Application.UnLock()
End Sub
</script>
然后我们简单写一个 test.ASPx 来查看 Application("TimeStamp") 的值。代码如下:
[VB.NET] test.ASPx
<%
Response.Write(Application("TimeStamp"))
%>
< meta http-equiv="Refresh" content="3;
url=http://www.cenpok.NET">
<script type="text/javascript"><!--google_ad_client = "pub-2947489232296736";/* 728x15, 创建于 08-4-23MSDN */google_ad_slot = "3624277373";google_ad_width = 728;google_ad_height = 15;//--></script><script type="text/javascript"src="http://pagead2.googlesyndication.com/pagead/show_ads.js"></script>
- 在 ASP.NET 中使用计时器(Timer)
- 在ASP.NET中使用计时器(Timer)
- 在 ASP.NET 中使用计时器(Timer)
- 在 ASP.NET 中使用计时器(Timer)
- ASP.NET中使用计时器(Timer)来实现群发邮件等功能
- ASP.Net Ajax框架 Timer控件 计时器
- 在 ASP.NET 中使用计时器执行用户代码(来源Internet)
- Android中timer(计时器)的使用
- ASP.NET AJAX入门系列(11):在多个UpdatePanle中使用Timer控件
- ASP.NET AJAX入门系列(11):在多个UpdatePanle中使用Timer控件
- ASP.NET AJAX入门系列:在多个UpdatePanle中使用Timer控件
- ASP.NET AJAX入门系列(11):在多个UpdatePanle中使用Timer控件
- ASP.NET AJAX入门系列(11):在多个UpdatePanle中使用Timer控件
- ASP.NET AJAX入门系列(11):在多个UpdatePanle中使用Timer控件
- ASP.NET AJAX入门系列(11):在多个UpdatePanle中使用Timer控件
- ASP.NET AJAX入门系列(11):在多个UpdatePanle中使用Timer控件
- ASP.NET AJAX入门系列(11):在多个UpdatePanle中使用Timer控件
- ASP.NET AJAX入门系列(11):在多个UpdatePanle中使用Timer控件
- aspx页面中标题单点解决方案
- 为XPath自定义函数(因为XPath1.0的函数非常有限)
- 如何在web.config中建立公用的的数据库连接
- 利用WebRequest来实现模拟浏览器通过Post方式向服务器提交数据
- ASP.NET2.0正式版中无刷新页面的开发(示例代码的补充)
- 在ASP.NET中使用计时器(Timer)
- ASP.NET2.0:Ilungasoft.Framework.Web之基于Callback的无刷新上传进度条控件[带源码]
- DataGrid实例(简单易懂,无复杂功能,适合初学者)
- 在ASP.NET页面中推荐使用覆写(Override)而不是事件处理(EventHandler)
- 使用ASP.NETAtlas编写显示真实进度的ProgressBar(进度条)控件
- Asp.Net中文本换行
- asp.net2.0中tablecontrol搭配masterpage的小bug
- 在ASP.NET中防止注入攻击[翻译]
- .NET应用程序的性能提升应用技巧