.net Timer定时执行
System.Timers.Timer可以实现数据库定时更新的功能
Global.asax
void Application_Start(object sender, EventArgs e)
{
// 在应用程序启动时运行的代码
System.Timers.Timer timer = new System.Timers.Timer(1000);
timer.Elapsed += new System.Timers.ElapsedEventHandler(AddCount);
//AddCount是一个方法,此方法就是每个1秒而做的事情
timer.AutoReset = true;
//给Application["timer"]一个初始值
Application.Lock();
Application["timer"] = 1;
Application.UnLock();
timer.Enabled = true;
}
private void AddCount(object sender, System.Timers.ElapsedEventArgs e)
{
Application.Lock();
Application["timer"] = Convert.ToInt32(Application["timer"]) + 1;
//这里可以写你需要执行的任务,比如说,清理数据库的无效数据或增加每个用户的积分等等
Application.UnLock();
}
页面中调用Global中定义的值
string time = Application["timer"].ToString();
Label1.Text = time;
.net Timer定时执行的更多相关文章
- Timer定时执行
//定时器 public void timeTask(String hh,int n) {//hh="8:30:00",n=12 Timer timer = new Timer() ...
- 使用System.Timers.Timer类实现程序定时执行
使用System.Timers.Timer类实现程序定时执行 在C#里关于定时器类有3个:System.Windows.Forms.Timer类.System.Threading.Timer类和Sys ...
- C#定时执行
代码: using System; using System.Collections.Generic; using System.ComponentModel; using System.Data; ...
- MVC 定时执行任务
环境:.net4.5 需求:需要一个方法定时执行任务 解决: System.Threading.Timer 提供以指定的时间间隔执行方法的机制. 此类不能被继承,有10多种实例化方法,满足多种情况. ...
- Java 在某一个时间点定时执行任务(转载)
java定时任务,每天定时执行任务.以下是这个例子的全部代码. public class TimerManager { //时间间隔 private static final long PERIOD_ ...
- 【ASP.NET 进阶】定时执行任务实现 (定时读取和修改txt文件数字内容,无刷新显示结果)
现在有很多网站或系统需要在服务端定时做某件事情,如每天早上8点半清理数据库中的无效数据等等,Demo 具体实现步骤如下: 0.先看解决方案截图 1.创建ASP.NET项目TimedTask,然后新建一 ...
- 【ASP.NET 进阶】定时执行任务
原理:利用全局应用程序类 Global.asax 和 System.Timers.Timer 类定时处理任务. 示例效果图: 其 Global.asax 类代码如下: using System; u ...
- JAVA定时执行任务,每天定时几点钟执行任务
JAVA定时执行任务,每天定时几点钟执行任务的示例如下: 1.建立TimerManage类,设置时间点,时间点设置的管理类,代码如下: package com.pcitc.time; import j ...
- 用Quartz处理定时执行的任务
这次做的项目中,有一部分功能需要实现定时执行.呃,这样说可能有点笼统,打个比方吧.例如用户在登录的时候,连续输错3次密码后,系统会将该用户冻结,不再允许该用户登录系统,等到了晚上零晨时分,再为所有被冻 ...
随机推荐
- C++Primer笔记-----day05
=======================================================================day05======================== ...
- Spyder kernel died 错误
Keras 2.2.4版本和 tensorflow1.2.1 版本不兼容导致的错误.降低Keras 为2.1.2版本 import keras 出现: Using TensorFlow backend ...
- /etc/rc5.d/s991local: line25: eject:command not found错误
使用虚拟机安装centos出现错误,原因是我使用的镜像是最小级别的,没有图形化界面,只有终端窗口 有人用vmware安装minimal centos报错/etc/rc5.d/s99local : ...
- excel解析的几种实现方法
- beego 中文教程
https://www.kancloud.cn/hello123/beego/126087
- Android——eclipse共享library以及导出jar包[转]
目录(?)[-] 一apk之间共享Class 二apk导出jar包 android的apk在在eclipse上进行开发的时候,有时候需要import其它包中的一些class,正常的方法就是在jav ...
- java算法 蓝桥杯算法训练 Fibonacci数列
问题描述 Fibonacci数列的递推公式为:Fn=Fn-1+Fn-2,其中F1=F2=1. 当n比较大时,Fn也非常大,现在我们想知道,Fn除以10007的余数是多少. 输入格式 输入包含一个整数n ...
- a Concise Sparse Matrix package
简明稀疏矩阵包 https://github.com/kulhanek/csparse https://github.com/kulhanek/csparse
- c# dynamic的属性是个变量
using System; using System.Collections.Generic; using System.Linq; using System.Text; using System.T ...
- mosquitto ---配置SSL/TLS linux
mosquitto ---配置SSL/TLS 摘自: https://www.cnblogs.com/saryli/p/9821343.html 在服务器电脑上面创建myCA文件夹, 如在/home/ ...