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. Flask学习总结笔记推荐

    https://blog.csdn.net/kikaylee/article/category/6551426

  2. 使用VMware 管理服务器

    使用VMware 管理服务器 实验室有一台浪潮服务器.师兄只留下了开机用户名和密码,和一个VMware vSphere Client的安装包,就把它托付给了我.就是这样一个方方正正的长方体,只提供了接 ...

  3. Codeforces Round #445 B. Vlad and Cafes【时间轴】

    B. Vlad and Cafes time limit per test 2 seconds memory limit per test 256 megabytes input standard i ...

  4. ZOJ 3949 (17th 浙大校赛 B题,树型DP)

    题目链接  The 17th Zhejiang University Programming Contest Problem B 题意  给定一棵树,现在要加一条连接$1$(根结点)和$x$的边,求加 ...

  5. Number Triangles

    题目描述 Consider the number triangle shown below. Write a program that calculates the highest sum of nu ...

  6. oracle中执行execute的时候报异常ORA-01031的解决办法

    在做实验的时候,编写关于"在存储过程中使用动态sql,建立一个统计表,并把统计结果,插入这个表中"的PL/sql语句在执行时出现权限不足的问题. 上网查询很多,看到了下面这篇博文( ...

  7. C语言基础之变量、作用域

    1.变量的定义 变量类型 变量名; int score; 2.变量的赋值 score = 100; score = a; score = b = 100; 3.变量的输出 int a = 200; p ...

  8. 在SQL Server中查看对象依赖关系

    原文 在SQL Server中查看对象依赖关系 Viewing object dependencies in SQL Server   Deleting or changing objects may ...

  9. debian下QT4编程环境的建立

    转:http://moosewoler.blog.163.com/blog/static/6986605200801013442336/ QT是一款跨平台的C++编程framework.QT的主要特性 ...

  10. ArcMAP定义投影坐标

    WGS84形式的高斯克吕格投影在ArcGIS系统中是不存在的,需要自己去定义.下面为MARK的定义过程.