vs.net2008 每三分钟执行次调用一个 函数 a(string par)
解决方案 »
- GridView的一个事件异常处理问题
- jquery 向cookie中写入 5 asp.net在后台读取怎么成%205了
- 这个Treeview的分层效果应该如何实现?
- 伪静态,url重写问题,在线等,急,求救啊...
- 求一个SQL查询
- 如何设定 GridView 控件固定有多行,尽管有些行的内容是空的?
- 绑定dropdownlist
- 有关web server里网络负载平衡中,会话数据和application对象数据共享的问题,请高手指教!!
- 公办学校紧急招聘(月薪不少于3000,有全部福利,可以调档案,5天工作制)
- 如何使邮件发送成功?
- NeatUpload控件,问题很严重!
- 错误的参数个数或无效的参数属性值: 'MD5'(SQL数据加密)
ASP.NET通过Global.asax和Timer定时器 定时调用WebService 运行后台代码
http://www.cnblogs.com/freeliver54/archive/2007/03/06/665625.aspx利使用global.asp定时执行ASP
http://www.cqzol.com/programming/64495.html
Private _interval As Double = 3 * 60 * 1000 Sub Application_Start(ByVal sender As Object, ByVal e As EventArgs)
' Fires when the application is started
Me._timer = New System.Timers.Timer( _interval)
AddHandler _timer.Elapsed, AddressOf a Me._timer.AutoReset = True
Me._timer.Enabled = True
Me._timer.Start()
End Sub
<%@ Import Namespace="System.Timers" %><script runat="server"> void Application_Start(object sender, EventArgs e)
{
// 在应用程序启动时运行的代码 Timer atimer = new Timer(10000); atimer.Elapsed += timer_execute; atimer.AutoReset = true;
atimer.Enabled = true;
Application.Lock();
Application["TimeStamp"] = DateTime.Now.ToString();
Application.UnLock();
} void timer_execute(object sender, EventArgs e) //定时执行的函数
{
Application.Lock();
Application["TimeStamp"] = DateTime.Now.ToString();
Application.UnLock();
}
</script>
采用TIMER控件,是可以做到,但存在一个很大问题:会无故停止TIMER事件。
以前曾经做过,再起一个监视TIMER,专用于监视另外的TIMER,使之不被停止,但仍然无法完全达到目的。你可以改用数据库的定时器,还是比较可靠的。
<head runat="server">
<title>无标题页</title>
</head>
<body>
<form id="form1" runat="server">
<div>
<asp:ScriptManager ID="ScriptManager1" runat="server">
</asp:ScriptManager>
<asp:Timer ID="Timer2" runat="server" Interval="3000" OnTick="Timer2_Tick">
</asp:Timer>
<asp:Label ID="Label1" runat="server" Text="Label"></asp:Label>
</div>
</form>
</body>
</html>
protected void Timer2_Tick(object sender, EventArgs e)
{
if(Session["test"]==null||Session["test"]=="")
{
Session["test"]=1;
}
int para=(int)Session["test"];
string strConnection = "Provider=Microsoft.Jet.OleDb.4.0;";
strConnection += @"Data Source=" + Server.MapPath("App_Data/test.mdb");
OleDbConnection objConnection = new OleDbConnection(strConnection);
objConnection.Open();
string sqlString = "Update testt Set test =" + para;
OleDbCommand cmd = new OleDbCommand(sqlString, objConnection);
cmd.ExecuteNonQuery();
objConnection.Close();
Label1.Text = "数据更新次数: " + Session["test"].ToString();
Session["test"]=para+1; }或者你可以搜索一下Timer的使用,楼上的资料也很详细了,呵呵 .希望可以帮到你.
请参照这个帖子实现定时操作