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 定时服务的更多相关文章

  1. VS2015 C#.net4.6 windows的定时服务

    1.创建项目 C#->经典桌面->windows服务 2.创建定时服务 找到服务1,自动生成了 OnStart(服务开启时运行),OnStop(服务关闭时运行)两个函数,我们需要在开启时新 ...

  2. LBPL--基于Asp.net、 quartz.net 快速开发定时服务的插件化项目

    LBPL 这一个基于Asp.net. quartz.net 快速开发定时服务的插件化项目 由于在实际项目开发中需要做定时服务的操作,大体上可以理解为:需要动态化监控定时任务的调度系统. 为了实现快速开 ...

  3. C# windows定时服务+服务邮箱发送

    protected override void OnStart(string[] args) { timer1 = new System.Timers.Timer(); // timer1 = new ...

  4. Spring MVC定时服务

    spring-mvc-config.xml <context:component-scan base-package="com.bf" ></context:co ...

  5. Spring定时服务QuartZ

    在JavaEE系统中,我们会经常用到定时任务,比如每天凌晨生成前天报表,每一小时生成汇总数据等等. 我们可以使用java.util.Timer结合java.util.TimerTask来完成这项工作, ...

  6. webscheduler 开源定时服务和延迟服务

    源码地址:https://gitee.com/eabeat/webscheduler 架构上采用 asp.net + access ,实现简单的管理界面,可以维护调用API,查看日志等功能.内核采用Q ...

  7. WebAPI项目添加定时服务

    开发平台: VS2019 背景: 在开发小程序的API服务的时候,由于access_token的有效期为7200秒,也就是2小时,这就需要后端定时的去更新这个access_token,便于调用小程序的 ...

  8. Python循环定时服务功能(相似contrab)

    Python实现的循环定时服务功能.类似于Linux下的contrab功能.主要通过定时器实现. 注:Python中的threading.timer是基于线程实现的.每次定时事件产生时.回调完响应函数 ...

  9. 【OF框架】使用OF.WinService项目,添加定时服务,进行创建启动停止删除服务操作

    准备 使用框架搭建完成项目,包含OF.WinService项目. 了解Window Service 和定时服务相关知识. 一.添加一个定时服务 第一步:了解项目结构 第二步:创建一个新的Job 第三步 ...

  10. 第九章 Net 5.0 快速开发框架 YC.Boilerplate --定时服务 Quartz.net

    在线文档:http://doc.yc-l.com/#/README 在线演示地址:http://yc.yc-l.com/#/login 源码github:https://github.com/linb ...

随机推荐

  1. 静态链接和动态链接库混用导致的链接错误LINK2005

    对于一个静态链接库L.lib,它的使用者app.exe会静态链接L.lib,意思是app.exe会将L.lib中的代码(app需要的部分,例如函数定义,类的定义等等)链接到app.exe中.   而对 ...

  2. c++不允许指向常量的指针赋值给不指向常量的指针

    #include <iostream> using namespace std; class A { public: int i; int j; } int main() { const ...

  3. PHP成生若干位防伪码的方法

    public static function createCode($length =16) { $arr = array_merge(range(0, 9), range('a', 'z')); / ...

  4. ActiveMQ StartUp

    从http://activemq.apache.org/activemq-5132-release.html 下载 解压 从apache-activemq-5.13.2\bin\win64\wrapp ...

  5. vs code 在windows10 64bit系统配置python开发环境

    一.搭建 python 环境 在 VSC 中点击 F1 键,弹出控制台,输入 ext install 界面左侧弹出扩展窗格,输入python,确认,开始搜索下载发布者为Don Jayamanne 的 ...

  6. SRM 733 Div 1 爆零记

    开场写easy(有预感要FST) 然后medium就卡住了. 我只知道$n$个点的生成树个数是$n^{n-2}$ 接下来直接狗带…… $Problem 250pts$ 水题,直接枚举然后记录答案(我大 ...

  7. 移动 web 1px 边框解决方案

    在移动端web页面开发中,为了使css中使用的尺寸与设计稿一致,通常会采用 rem 单位配合 lib-flexible 来实现移动端的适配,在IOS设备上 flexible.js 会根据设备的分辨率动 ...

  8. Vue + Webpack + Vue-loader 系列教程

    http://www.cnblogs.com/terry01/p/5953464.html 介绍 Vue-loader 是什么? vue-loader 是一个加载器,能把如下格式的 Vue 组件转化成 ...

  9. Kyle 的 iOS 面试题

    1.简单介绍下你对swizzling方法的了解,一般你什么时候使用. 2.有三个对象 A,B,C..:A retain B, B retain C, C retain B..当 A release B ...

  10. 【Linux】Linux下 环境变量/etc/profile、/etc/bashrc、~/.bashrc的区别【转】

    转自:http://blog.csdn.net/qiao1245/article/details/44650929 ------------------------------------------ ...