.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语言清空输入缓冲区的N种方法对比(转)
C语言中有几个基本输入函数: //获取字符系列 int fgetc(FILE *stream); int getc(FILE *stream); int getchar(void); //获取行系列 ...
- Hibernate中Session.save()方法的返回值是什么
public Serializable save(Object object) Parameters: object - a transient insta ...
- [iOS]swift版内购
//内购Demo,看代码说话吧 class IAPTestViewController: UIViewController ,SKProductsRequestDelegate, SKPaymentT ...
- T-SQL 重复读(Double Read)问题的理解
我的理解是: step1,假设表里有100行有序记录, 事务1从row 1 开始读取到了row 50 并准备继续读取完这100行. 要注意的是,sql server 会自动释放已经读取了的row的锁. ...
- redis centos7
官网下载tar包 make 修改conf 修改 启动脚本 utils/redis_init_script 开放端口6379
- Solo and Mute
[Solo and Mute ] Muting means a transition will be disabled. Soloed transtions are enabled and with ...
- [cogs2638]数列操作ψ(双标记线段树)
题目大意:给定一个数列a,你需要支持的操作:区间and,区间or,询问区间最大值 解题关键: 1.双标记线段树,注意优先级(超时) 当涉及多重标记时,定义出标记的优先级,修改操作时用优先级高(先下放) ...
- spring4-4-jdbc-02
1.简化 JDBC 模板查询 每次使用都创建一个 JdbcTemplate 的新实例, 这种做法效率很低下. JdbcTemplate 类被设计成为线程安全的, 所以可以再 IOC 容器中声明它的单个 ...
- 19-字符切割函数c++模板
https://www.cnblogs.com/stonebloom-yu/p/6542756.html #include <cstring> #include <cstdio> ...
- wireshark问题
上一篇wireshark编译成功了,生成了相应的wireshark.exe,dumpcap.exe等可执行文件(这些文件都是可以运行的),编译工具用的是VS2010,但是新生成的文件和文件夹中没有找到 ...