.net 定时服务
namespace MvcApplication1 {
public class MvcApplication : System.Web.HttpApplication
{
protected void Application_Start()
{
AreaRegistration.RegisterAllAreas();
WebApiConfig.Register(GlobalConfiguration.Configuration);
FilterConfig.RegisterGlobalFilters(GlobalFilters.Filters);
RouteConfig.RegisterRoutes(RouteTable.Routes);
Time_Task.Instance().ExecuteTask += new System.Timers.ElapsedEventHandler(Global_ExecuteTask);
Time_Task.Instance().Interval = 1000 * 60;//表示间隔1分钟
Time_Task.Instance().Start();
//Time_Task.Instance().Stop();//结束定时
}
public void Global_ExecuteTask(object sender, System.Timers.ElapsedEventArgs e) {
//在这里编写需要定时执行的逻辑代码
}
}
public class Time_Task {
public event System.Timers.ElapsedEventHandler ExecuteTask;
private static readonly Time_Task _task = null;
private System.Timers.Timer _timer = null;
private int _interval = 1000;
public int Interval {
set { _interval = value; }
get { return _interval; }
}
static Time_Task() {
_task = new Time_Task();
}
public static Time_Task Instance() {
return _task;
}
public void Start() {
if (_timer == null)
{
_timer = new System.Timers.Timer(_interval);
_timer.Elapsed += new System.Timers.ElapsedEventHandler(_timer_Elapsed);
_timer.Enabled = true;
_timer.Start();
}
}
protected void _timer_Elapsed(object sender, System.Timers.ElapsedEventArgs e) {
if (null != ExecuteTask)
{
ExecuteTask(sender, e);
}
}
public void Stop()
{
if (_timer != null)
{
_timer.Stop();
_timer.Dispose();
_timer = null;
}
}
}
}
.net 定时服务的更多相关文章
- VS2015 C#.net4.6 windows的定时服务
1.创建项目 C#->经典桌面->windows服务 2.创建定时服务 找到服务1,自动生成了 OnStart(服务开启时运行),OnStop(服务关闭时运行)两个函数,我们需要在开启时新 ...
- LBPL--基于Asp.net、 quartz.net 快速开发定时服务的插件化项目
LBPL 这一个基于Asp.net. quartz.net 快速开发定时服务的插件化项目 由于在实际项目开发中需要做定时服务的操作,大体上可以理解为:需要动态化监控定时任务的调度系统. 为了实现快速开 ...
- C# windows定时服务+服务邮箱发送
protected override void OnStart(string[] args) { timer1 = new System.Timers.Timer(); // timer1 = new ...
- Spring MVC定时服务
spring-mvc-config.xml <context:component-scan base-package="com.bf" ></context:co ...
- Spring定时服务QuartZ
在JavaEE系统中,我们会经常用到定时任务,比如每天凌晨生成前天报表,每一小时生成汇总数据等等. 我们可以使用java.util.Timer结合java.util.TimerTask来完成这项工作, ...
- webscheduler 开源定时服务和延迟服务
源码地址:https://gitee.com/eabeat/webscheduler 架构上采用 asp.net + access ,实现简单的管理界面,可以维护调用API,查看日志等功能.内核采用Q ...
- WebAPI项目添加定时服务
开发平台: VS2019 背景: 在开发小程序的API服务的时候,由于access_token的有效期为7200秒,也就是2小时,这就需要后端定时的去更新这个access_token,便于调用小程序的 ...
- Python循环定时服务功能(相似contrab)
Python实现的循环定时服务功能.类似于Linux下的contrab功能.主要通过定时器实现. 注:Python中的threading.timer是基于线程实现的.每次定时事件产生时.回调完响应函数 ...
- 【OF框架】使用OF.WinService项目,添加定时服务,进行创建启动停止删除服务操作
准备 使用框架搭建完成项目,包含OF.WinService项目. 了解Window Service 和定时服务相关知识. 一.添加一个定时服务 第一步:了解项目结构 第二步:创建一个新的Job 第三步 ...
- 第九章 Net 5.0 快速开发框架 YC.Boilerplate --定时服务 Quartz.net
在线文档:http://doc.yc-l.com/#/README 在线演示地址:http://yc.yc-l.com/#/login 源码github:https://github.com/linb ...
随机推荐
- ObjectInputStream&ObjectOutputStream工具类
序列化:将数据保存到文件:ObjectOutputStream; 反序列化:将文件中的数据显示出来:ObjectInputStream; 在反序列化程序中运行后能够正常输出Person的相关信息, ...
- Appium+python自动化7-输入中文【转载】
前言 在做app自动化过程中会踩很多坑,咱们都是用的中文的app,所以首先要解决中文输入的问题! 本篇通过屏蔽软键盘,绕过手机的软键盘方法,解决中文输入问题. 一.定位搜索 1.打开淘宝点搜索按钮,进 ...
- xxx.service is not a native service, redirecting to /sbin/chkconfig.
centos7编译安装的程序无法用systemctl 启动 [root@nagios-server check_commands]# systemctl enable npcd.service npc ...
- GitHub和GitLab的区别 转自(zhang_oracle)
把代码从GitHub上迁移到GitLab上,在使用一段时间过后,发现GitLab与GitHub还是有不少区别的. 先说一下相同点,二者都是基于web的Git仓库,在很大程度上GitLab是仿照GitH ...
- Shellcode开发辅助工具shellnoob
Shellcode开发辅助工具shellnoob Shellcode开发的过程中会遇到很多繁杂的工作,如编译.反编译.调试等.为了减少这部分工作,Kali Linux提供了开发辅助工具shelln ...
- TestList汇总
[基本类型] 类的构造方法调用问题 重载复写的区别 Final finally finalized 的区别 定义final变量是否需要初始化 forward和redirect的区别 equals方法和 ...
- 动态规划 001 - 编辑距离(Levenshtein Distance)问题
问题 字符串的编辑距离也被称为距Levenshtein距离(Levenshtein Distance),属于经典算法,常用方法使用递归,更好的方法是使用动态规划算法,以避免出现重叠子问题的反复计算,减 ...
- java多线程设计模式(3)读写锁模式
1 Read-Write Lock Pattern Read-Write Lock Pattern是一种将对于共享资源的访问与修改操作分离,称为读写分离.即访问是reader,修改是write,用单独 ...
- VUE -- 安装新模块
- [置顶]
docker--基础镜像和dockerfile
制作基础镜像 注意:需要在CentOS6下操作 准备工作 yum -y install febootstrap 下载ISO镜像文件到服务器 mkdir /mnt/centos6/ mount -o l ...