.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 ...
随机推荐
- 优化html中mp4视频加载速度
如果使用参数faststart就会在生成完上边结构之后将moov移动到mdat前面:ffmpeg –i input.flv –c copy –f mp4 –movflags faststart out ...
- 控制台注入DLL代码
// zhuru.cpp : 定义控制台应用程序的入口点. #include "stdafx.h" #include <Windows.h> #define GameC ...
- 转载——为Xamarin更好的开发而改写的库
本人现今一直奋战在Xamarin.Android,可能有人会疑惑Xamarin本身就是跨平台的,为什么不能直接跨IOS和Android,这个当然是最后的目标,只是现今你连Android都不能拿出符合商 ...
- 计蒜客 25985.Goldbach-米勒拉宾素数判定(大素数) (2018 ACM-ICPC 中国大学生程序设计竞赛线上赛 B)
若干年之前的一道题,当时能写出来还是超级开心的,虽然是个板子题.一直忘记写博客,备忘一下. 米勒拉判大素数,关于米勒拉宾是个什么东西,传送门了解一下:biubiubiu~ B. Goldbach 题目 ...
- python 将windows字体中的汉字生成图片的方法
#encoding: utf-8import osimport pygame chinese_dir = '黑体常规'if not os.path.exists(chinese_dir): os.mk ...
- Activator常用方法
1.获取图片 public static Image getImage(String key) { Image img = getDefault().getImageRegistry() ...
- URl 传参时+号变成空格
前端用base64加密后的数据,传递到后台时发现一个问题: 比如 韩飞 这个名字,base64加密后的字符串为 6Z+p6aOe 但是后端接受到参数为: 6Z p6aOe +号变成了空格,导致后台解密 ...
- 前端常用面试题目及答案-HTML&CSS篇
1. 行内元素和块级元素有哪些? 行内元素: 123456789101112131415161718192021222324252627 <a> //标签可定义锚 <ab ...
- luogu P3819 松江1843路
题目描述 涞坊路是一条长L米的道路,道路上的坐标范围从0到L,路上有N座房子,第i座房子建在坐标为x[i]的地方,其中住了r[i]人. 松江1843路公交车要在这条路上建一个公交站,市政府希望让最多的 ...
- 如何隐藏 video 元素的下载按钮
1. 使用 video 元素的 ControlList API <video controls controlsList="nodownload"></video ...